GHC fails to infer type with FlexibleContexts
If I say
{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts #-}
module Bug where
class C a b where
op :: a -> b -> ()
-- foo :: (C a Integer) => a -> ()
foo x = op x 3
then GHC complains that the variable b0
in the type of foo
is ambiguous, because it tries to produce C a b => a -> ()
as the type of foo
. Instead, it shouldn't quantify b
, letting it default to Integer
.
The solution is to use oclose
instead of growThetaTyVars
in decideQuantifiedTyVars
. This will respect functional dependencies, quantifying over b
only when a fundep exists from a
to b
.
I will fix in ongoing work (in the wip/derived-refactor
branch).