[Haskell-cafe] Can't resolve class dependences (making Boolean class)

Grigory Sarnitskiy sargrigory at ya.ru
Tue Sep 13 15:04:07 CEST 2011


Hello! I'm trying to have a class for booleans called Boolean (the methods are not complete):

class MyEq a where
    (===) :: (Boolean b) => a -> a -> b

class (MyEq a) => Boolean a where
    (/\) :: a -> a -> a

instance MyEq Bool where
    x === y = x==y

instance Boolean Bool where
    (/\) = (&&)

However, to make Bool an instance of Boolean I need to make it an instance of MyEq first, which I can't, because to define === I need Bool to be in Boolean. Indeed the code above give the error:

    Could not deduce (b ~ Bool)
    from the context (Boolean b)
      bound by the type signature for
                 === :: Boolean b => Bool -> Bool -> b
      at 1.hs:8:5-18
      `b' is a rigid type variable bound by
          the type signature for === :: Boolean b => Bool -> Bool -> b
          at 1.hs:8:5
    In the expression: x == y
    In an equation for `===': x === y = x == y
    In the instance declaration for `MyEq Bool'
Failed, modules loaded: none.


How can I overcome the issue?



More information about the Haskell-Cafe mailing list