[Haskell] GHC Error question

Simon Peyton-Jones simonpj at microsoft.com
Tue Dec 5 18:12:26 EST 2006

[redirecting to ghc users]

It looks like a splendid error to me.  The call of compile1 is obliged to pass to compile1 a dictionary of type (Builder b box), *for any type box*.  There are no further constraints on box, so compile1 can make no assumptions about how the caller chooses to instantiate 'box'.

But in the body you'll need a dictionary of type (Builder b box1), but there is nothing to ensure that the caller chooses the "right" box.

Maybe you want the Builder class to have a functional dependency (b -> box), so that fixing b fixes box.

I can't say more without seeing the code.  can you give a small repo case?


| -----Original Message-----
| From: haskell-bounces at haskell.org [mailto:haskell-bounces at haskell.org] On Behalf Of Norman
| Ramsey
| Sent: 05 December 2006 21:21
| To: haskell at haskell.org
| Cc: nr at eecs.harvard.edu
| Subject: [Haskell] GHC Error question
| Without going too deep into the details of my type classes, I have
| written the following code (focusing on compile1):
|   {-# OPTIONS -fglasgow-exts #-}
|   compile1 :: (Builder b box) => t -> Name -> Ir.ANF -> b t
|   compile1 f x body = do env <- compile body empty
|                          wire (Arg W) (env x)
|                          return f
|   compile :: (Builder b box) => Ir.ANF -> Env box -> b (Env box)
|   class (Monad b) => Builder b box where
|     wire            :: Source box -> Sink box -> b ()
|     ...
|   type Env box = Name -> Sink box
| This program is rejected by GHC with the following message:
| Ccomp.hs:54:23:
|     Could not deduce (Builder b box1) from the context (Builder b box)
|       arising from use of `wire' at Ccomp.hs:54:23-42
|     Possible fix:
|       add (Builder b box1) to the type signature(s) for `compile1'
|     In the expression: wire (Arg W) (env x)
|     In a 'do' expression: wire (Arg W) (env x)
|     In the expression:
|         do env <- compile body empty
|            wire (Arg W) (env x)
|            return f
| Note that compile1 has an explicit type signature much along the lines
| suggested by GHC.  If I *remove* this type signature, the function
| compiles successfully, and ghci reporets this type for compile1:
|   compile1 :: (Builder t box) => t1 -> Name -> Ir.ANF -> t t1
| I believe this signature is isomorphic to the explicit signature I had
| attempted to use.
| Am I misusing the type-class system in some way, or should I be
| reporting a bug in GHC?
| Norman
| _______________________________________________
| Haskell mailing list
| Haskell at haskell.org
| http://www.haskell.org/mailman/listinfo/haskell

More information about the Glasgow-haskell-users mailing list