[Haskell-cafe] Re: Trying to understand HList / hSequence now [why it works]

Bulat Ziganshin bulat.ziganshin at gmail.com
Wed Oct 11 02:43:25 EDT 2006

Hello oleg,

Wednesday, October 11, 2006, 6:45:28 AM, you wrote:

>> instance (Monad m, HSequence m HNil HNil) => HSequence m HNil HNil
>>     where hSequence _ = return HNil
>> how can i use the goal of the declaration as one of the conditions
>> without causing some sort of black hole in the type inference
>> algorithm?

> Very easily: the instance head is implicitly the part of its own
> context (so that a method can be recursive).

as an example:

data T = C

instance Eq T where
  C==C = True
  (/=) = not (==)

instance declarations may be even mutually recursive:

instance Eq T where
  a==b          = compare a b == EQ

instance Ord T where
  compare a b   = EQ
  a<b           = compare a b == LT
  a<=b          = (a<b) || (a==b)

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list