
Grzegorz A nice example! I don't think I'd really realised before that a type like forall a. (?x::a) => Int is not ambiguous at all, even though the Int part does not mention the 'a'. Why not? Because a call site will give the ?x binding, and that in turn fixes a. I've fixed GHC (the HEAD) to allow this. The patch is in an area that I have upheaved recently, so I doubt it'll appear in 6.6.1. Use the HEAD, or wait for 6.8. Thanks for suggesting this. Your example (and name) are immortalised in the regression test suite. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of | Grzegorz Chrupala | Sent: 16 November 2006 16:10 | To: Haskell Cafe | Subject: [Haskell-cafe] Implicit params and typeclasses | | 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? | | Thanks, | -- | Grzegorz | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe