Opened 3 months ago

Last modified 3 months ago

#13853 new feature request

TypeApplications and record syntax don't mix

Reported by: RyanGlScott Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.1
Keywords: TypeApplications Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by RyanGlScott)

Let's fire up GHCi:

$ ~/Software/ghc-
GHCi, version  :? for help
Loaded GHCi configuration from /Users/rscott/.ghci
λ> :set -XTypeApplications -fprint-explicit-foralls 
λ> import Data.Functor.Identity

I can use TypeApplications on Identity like so:

λ> Identity @Int 42
Identity 42

But not if I try to use record syntax:

λ> Identity @Int { runIdentity = 42 }

<interactive>:4:15: error: parse error on input ‘{’

Change History (6)

comment:1 Changed 3 months ago by RyanGlScott

Description: modified (diff)

comment:2 Changed 3 months ago by goldfire

Record-construction syntax is not a special application form, so I wouldn't expect this to work. Perhaps we can embellish record-construction to enable this syntax, but it would be a change to the grammar.

This smells similar to #12363, asking for type application on infix operators.

I think the next step here is a ghc-proposal.

comment:3 Changed 3 months ago by Iceland_jack

Hm this is confusing

> Identity { runIdentity = 42 }
Identity 42
> (Identity) { runIdentity = 42 }

<interactive>:21:1: error:
    • Couldn't match expected type ‘Identity a1’
                  with actual type ‘a0 -> Identity a0’
    • In the expression: (Identity) {runIdentity = 42}
      In an equation for ‘it’: it = (Identity) {runIdentity = 42}

comment:4 Changed 3 months ago by goldfire

comment:3 follows directly from the Report. Note that (Identity {}) { runIdentity = 42 } works: a record construction (with an empty field-list) followed by a record-update.

comment:5 Changed 3 months ago by Iceland_jack

Identity @Int {} would work as well then?

comment:6 Changed 3 months ago by RyanGlScott

Assuming the proposal in this ticket were implemented, then yes, Identity @Int {} would be a perfectly cromulent thing to do. Identity {} is a record construction that doesn't specify any record names, so all fields would be initialized to . So Identity @Int {} is essentially Identity (⊥ :: Int).

Note: See TracTickets for help on using tickets.