How to do pattern binding in instance declarations?

My code is quite simple:

data Direction a = North a | South

instance (Bounded tc) => Bounded (Direction tc) where
    maxBound::(Direction tc)  = North dc  where dc = maxBound::tc
    minBound::(Direction tc)  = South

But I got the following error:

<interactive>:56:5: error:
    Pattern bindings (except simple variables) not allowed in instance declaration:
      maxBound :: (Direction tc)
        = North dc
        where
            dc = maxBound :: vtc

<interactive>:57:5: error:
    Pattern bindings (except simple variables) not allowed in instance declaration:
      minBound :: (Direction tc) = South

Maybe you’re just not allowed to do that? As an alternative you can use a scoped type variable:

instance forall tc. (Bounded tc) => Bounded (Direction tc) where
    maxBound = North dc  where dc = maxBound::tc
    minBound = South
instance (Bounded tc) => Bounded (Direction tc) where
    maxBound = North maxBound
    minBound = South

works with the same meaning as well, but I am not sure if op was producing a contrived example to illustrate the question. The class provides the definition so I think coercing the type like that cannot make sense?

Your code does work! But how do I konw the second

maxBound

of the statement

maxBound = North maxBound

is the maxBound of the type construtor

tc

For me, It is more reasonable to interpret the statement

maxBound = North maxBound

as a recursive definition where maxBound relays on itself.

Thank you, this does solved my problem. I search for what is

forall

in haskell, and realize the type variable tc within the instance declaration and type variable tc within the instance definition are not the same if forall not used.