purescript / purescript-record

Functions for working with records and polymorphic labels
BSD 3-Clause "New" or "Revised" License
69 stars 31 forks source link

Record kind as type parameter? Bug? #48

Closed chrisdone closed 6 years ago

chrisdone commented 6 years ago

The following works:

generate :: forall r. { | r} -> { x :: Int | r }
generate = ?a

But this doesn't:

data E (a :: # Type) = E
generate :: forall r. E { | r} -> E { x :: Int | r }
generate = ?a
Could not match kind

     # Type

   with kind

     Type

What am I doing wrong? It seems like the kind of the parameter of E is ignored and that the forall r is defaulting to Type instead of # Type. However,

generate :: forall (r :: # Type). E { | r} -> E { x :: Int | r }
 Mai...    59  20 error    Err...   Unable to parse module:
   unexpected (
   expecting identifier

kind signatures in a forall don't seem to be supported. What do I do?

chrisdone commented 6 years ago

Rephrasing to avoid an X/Y problem, here's what I'm trying to achieve:

E is an expression in some language, the r might contain location information or something like that.

data E r = E r
generate :: E r -> E { typ :: Typ | r }

I want that the E type already contains some record, that we don't know. Then generate is going to insert an additional type annotation of everything in E as the field typ :: Typ. Is this achievable with PureScript's type system?

chrisdone commented 6 years ago

Sorry, asked in the wrong repo. Moving to purescript.