[Haskell-cafe] Typeclasses and implicit parameters

Simon Peyton-Jones simonpj at microsoft.com
Thu Sep 6 05:29:12 EDT 2007

| -- Hugs allows this.  GHC rejects it on the grounds that "a" is unused
| -- on the right-hand side of the (=>).  I think this is arguably a bug
| -- in GHC.
| f3 :: (Show a, ?foo :: a) => String
| f3 = show ?foo

Hugs is right here.  GHC 6.8 accepts this too, and has done for some time; there's even a test in the test suite (tc218).

| -- GHC rejects this.  Hugs compiles it, but I can't call it as
| -- let ?foo = "Hello" in show Foo
| --
| -- Is there a good reason to disallow this?
| data Foo = Foo
| instance (?foo :: String) => Show Foo where
|     showsPrec _ Foo = showString ?foo . showString "Foo"

This should be illegal.  The way in which implicit parameters are bound depends on the call site of teh overloaded function.  E.g. the call site of f3 above  affects the value of ?foo.

For an instance declaration, the "call site" is unknown -- it's wherever the type checker chooses to simplify the constraint.  No implicit parameters in instance contexts!  This is documented in GHC's user manual Section


More information about the Haskell-Cafe mailing list