ghci 5.00 instance declaration error

Simon Peyton-Jones simonpj at microsoft.com
Thu Nov 1 08:11:03 EST 2001


You're right that the error message is confusing, but I think
the program is indeed erroneous. 

The error arises from the defn of mzip in the instance decl, so
it's entirely reasonable that it goes away if you don't give
a defn (then GHC plugs in an error message instead).

The defn of mzip is

    mzip as bs cs = mzip (mzip as bs) cs 

Trouble is, the inner call to mzip gives rise to the constraint
	MZip (as -> bs -> t)
where t is entirely unconstrained.   The outer call to mzip gives
a similar constraint.  There's no way to connect these unconstrained
t's with the 'ds' that you pass in the instance declaration.

Fortunately, GHC has scoped type variables, so you can simply say

	mzip as bs cs = mzip (mzip as bs :: ds) cs 

and bingo it compiles.



The question for me is how to improve the original error 
message.  Really the constraints are never going to be 
satisfiable because t is ambiguous.  I've been meaning
to imrove the reporting of ambiguous constraints for a while.

Simon

| -----Original Message-----
| From: Martin Sulzmann [mailto:sulzmann at cs.mu.OZ.AU] 
| Sent: 29 October 2001 04:53
| To: glasgow-haskell-bugs at haskell.org
| Subject: ghci 5.00 instance declaration error
| 
| 
| Consider the following program:
| 
| --------------------
| 
| module MZip where
| 
| class MZip a where mzip :: a
| 
| instance (MZip (as->bs->ds), MZip(ds->cs->r)) => MZip 
| (as->bs->cs->r) where
|    mzip as bs cs = mzip (mzip as bs) cs 
| 
| ----------------------------
| 
| I get the following error message:
| 
| Compiling MZip             ( MZip2.hs, interpreted )
| 
| MZip2.hs:9:
|     Could not deduce `MZip (t -> cs -> r)'
|         from the context (MZip (as -> bs -> cs -> r),
|                           MZip (as -> bs -> ds),
|                           MZip (ds -> cs -> r))
|     Probable fix:
|         Add `MZip (t -> cs -> r)' to the instance declaration context
|         Or add an instance declaration for `MZip (t -> cs -> r)'
|     arising from use of `mzip' at MZip2.hs:9
|     in the definition of function `mzip': mzip (mzip as bs) cs
| 
| MZip2.hs:9:
|     Could not deduce `MZip (as -> bs -> t)'
|         from the context (MZip (as -> bs -> cs -> r),
|                           MZip (as -> bs -> ds),
|                           MZip (ds -> cs -> r))
|     Probable fix:
|         Add `MZip (as -> bs -> t)' to the instance declaration context
|         Or add an instance declaration for `MZip (as -> bs -> t)'
|     arising from use of `mzip' at MZip2.hs:9
|     In the first argument of `mzip', namely `(mzip as bs)'
|     in the definition of function `mzip': mzip (mzip as bs) cs
| 
| 
| I used ghci -fglasgow-exts -fallow-undecidable-instances
| 
| 
| Note that If I use only (empty instance declaration)
| 
| instance (MZip (as->bs->ds), MZip(ds->cs->r)) => MZip (as->bs->cs->r) 
| 
| everything works fine.
| 
| Why do I get an error message of I include the body of the 
| where statement? Is there a form of skolemization happening? 
| It seems to me a limitation of the implementation. 
| 
| Martin
| 
| 
| 
| _______________________________________________
| Glasgow-haskell-bugs mailing list 
| Glasgow-haskell-bugs at haskell.org 
| http://www.haskell.org/mailman/listinfo/glasgow-| haskell-bugs
| 




More information about the Glasgow-haskell-bugs mailing list