[Haskell-cafe] Ambiguous type variable ‘f0’ arising from a use of ‘f’

Richard Eisenberg eir at cis.upenn.edu
Sun Mar 20 18:47:18 UTC 2016


GHC 8 does implicit quantification a little differently than previous versions. Previously, writing `=>` in a type meant that GHC looked through the type for free variables and put an implicit `forall` for those variables out front. GHC 8 doesn't do this, explaining the first change. There seems to be no documentation about this (intentional) change; I've filed #11726 requesting documentation.

As for the second change, GHC 7.10 should not have accepted the old program, as it was incorrect. The problem is that GHC must infer types for f' and g'. These types are constrained (they have `Applicative f =>`). They have no type signature, nor are they declared using function syntax. Thus, the monomorphism restriction applies, causing chaos. I bet enabling -XNoMonomorphismRestriction would allow you to undo the second change.

Another common workaround to the monomorphism restriction is to add a type signature. But this doesn't work in the presence of pattern bindings, which is filed as #11339.

I hope this helps!
Richard

On Mar 19, 2016, at 7:03 PM, Tom Ellis <tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:

> Can anyone explain what happened in GHC 8 such that it forced this change:
> 
>    -data PackMap a b s t = PackMap (Applicative f => (a -> f b) -> s -> f t)
>    +data PackMap a b s t = PackMap (forall f. Applicative f => (a -> f b) -> s -> f t)
> 
>   ...
> 
>     instance PP.SumProfunctor (PackMap a b) where
>    -  f +++! g = (PackMap (\x -> eitherFunction (f' x) (g' x)))
>    -    where PackMap f' = f
>    -          PackMap g' = g
>    +  f +++! g =
>    +    PackMap (\x ->
>    +               case f of
>    +                 PackMap f' ->
>    +                   case g of
>    +                     PackMap g' ->
>    +                       eitherFunction (f' x)
>    +                                      (g' x))
> 
>    https://github.com/tomjaguarpaw/haskell-opaleye/pull/140/files
> 
> The errors are
> 
>    Ambiguous type variable ‘f0’ arising from a use of ‘f’
> 
> etc., as seen here
> 
>    https://github.com/tomjaguarpaw/haskell-opaleye/pull/140#issuecomment-198297953
> 
> Thanks,
> 
> Tom
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> 



More information about the Haskell-Cafe mailing list