unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

Forall types in a record don't work the same as non-records. #5377

Open ChrisPenner opened 1 month ago

ChrisPenner commented 1 month ago

I attempted to define:

structural type Functor f = 
  {map : forall a b. (a -> b) -> f a -> f b }

Which failed with:

  I found a value  of type:  (a1 -> b1) -> 𝕣
  where I expected to find:  (a -> b) -> f a -> f b

      2 |   {map : forall a b. (a -> b) -> f a -> f b }

    from right here:

      2 |   {map : forall a b. (a -> b) -> f a -> f b }

Reconfiguring it as not-a-record works:

structural type Functor f = 
  Functor (forall a b. (a -> b) -> f a -> f b)
pchiusano commented 1 month ago

This is a dupe of some issue that I can't locate. It's caused because the record accessors have inferred types, and higher-rank types are never inferred. (A record accessor can have pretty complicated type since it's allowed to change type parameters, so it's not simple to figure out what type we should ascribe to them)

I think more and more we should just do proper record types.