[Haskell-cafe] Implicit params and typeclasses

Grzegorz Chrupała grzegorz.chrupala at computing.dcu.ie
Thu Nov 16 11:09:42 EST 2006

Hi all,
When I try to compile the following in GHC (v 6.6) (with
-fno-monomorphism-restriction -fimplicit-params)
class Configuration a where
    thestring:: a -> String
foo c = let { ?c = c } in bar
bar = thestring ?c
I get:
    Ambiguous type variable `a' in the constraint:
      `Configuration a'
	arising from use of `thestring' at /home/grzegorz/Foo.hs:9:6-17
    Possible cause: the monomorphism restriction applied to the following:
      bar :: (?c::a) => String (bound at /home/grzegorz/Foo.hs:9:0)
      foo :: a -> String (bound at /home/grzegorz/Foo.hs:8:0)
    Probable fix: give these definition(s) an explicit type signature
		  or use -fno-monomorphism-restriction

Adding the type signature bar :: (Configuration a,?c :: a) => String
the compiler says:
    Ambiguous constraint `Configuration a'
	At least one of the forall'd type variables mentioned by the constraint
	must be reachable from the type after the '=>'
    In the type signature for `bar':
      bar :: (Configuration a, ?c :: a) => String

Similar code without use of implicit params compiles fine:
class Configuration a where
    thestring:: a -> String
foo c = thestring c

Why do implicit params cause this error and is there a way to make it work?


More information about the Haskell-Cafe mailing list