[Haskell-cafe] Multi-parameter type class woes

Christopher Lane Hinson lane at downstairspeople.org
Sun Dec 14 23:51:04 EST 2008

On Sun, 14 Dec 2008, Mario Bla?evi? wrote:

>> I'll take a swing at this one:
>> instance Container (Maybe x) [x] where
>> wrapper = isNothing
>> . . .
>> That isn't a sensible definition of 'wrapper', but I believe without
>> trying to compile it is completely legal.  Which wrapper do you use?
>> You /don't/ have a different matching Container instance, but without the
>> functional dependency you /might/, and ghc barfs.
>    But liftWrap doesn't require any particular instance, it's a
> generic function accepting any pair of types for which there is
> an instance of Container. Instance selection (as I understand it)
> shouldn't come into play until one applies liftWrap to a
> particular type, and indeed it does cause problems there: note
> the type annotations on the last line. That part I understand
> and accept, or at least have learned to live with.

Yes, that is an intuitive understanding to us humans, but the instance 
selection applies seperately for 'wrapper' and 'listWrap'; ghc doesn't 
automatically prefer a particular instance just because it is in the 
context of the calling function.


More information about the Haskell-Cafe mailing list