Field accessor type inference woes

Twan van Laarhoven twanvl at gmail.com
Tue Jul 2 16:26:07 CEST 2013


On 02/07/13 10:57, Simon Peyton-Jones wrote:
> Here is Plan A: use fundep (or type function)
>
>     class Has r f t | r f -> t where
>         getFld :: r -> t
>
>     instance Has (R a) “foo” (a -> a) where ..
>     instance Has S “bar” (forall b. b -> b) where ...
>
> Lacking (as we still do) impredicative polymorphism, the S instance declaration
> is rejected.

How common are such polymorphic fields in practice? You sometimes see them in 
newtype wrappers and the like. But I think those are not cases where you want 
overlapping names anyway.

So: why not use a Plan A style class, except for polymorphic fields? Perhaps you 
could still have a (less polymorphic) class for bar above,

     class HasBar r where
         getBar :: r -> b -> b


Twan



More information about the Glasgow-haskell-users mailing list