So, when I compile the following piece of code edited:
instance (Eq a) => PartOrd a where
[] == [] = True
(x:xs) == (y:ys) = x==y && xs==ys
_ == _ = False
xs /= ys = not (xs == ys)
I get:
`==' is not a (visible) method of class 'PartOrd'
`/=' is not a (visible) method of class 'PartOrd'
Failed, modules loaded: none.
I have looked at How to properly instantiate classes in Haskell? for some clarifications but even though I wasn`t able to fix it.
Also, is it the same when I use custom-made operators such as =~ for == and /~ for /=, because I get the same error?
EDIT: As requested:
class Eq a => PartOrd a where
partcmp :: a -> a -> Maybe Ordering
partcmp x y = case bigger x y of
True -> Just LT
False -> case smaller x y of
True -> Just GT
False -> case x == y of
True -> Just EQ
False -> Nothing
It isn't clear what you are trying to achieve. Here are some thoughts:
When you declare an instance of a class like
instance (Eq a) => PartOrd a, you are expected to provide implementations for the functions inPartOrd a(iepartcmp, not==and/=). The compiler is telling you exactly that:==and/=are in the classEq, notPartOrd, and you have no business defining functions not inPartOrd. In fact, no matter whether you use==, or=~or/~, the problem persists: you shouldn't be defining anything other thatpartcmpininstance (Eq a) => PartOrd a. The(Eq a) =>part just says that in these definitions you can assume functions==and/=of type signatures(==), (/=) :: a -> a -> ahave been defined.Why are you using lists in the instance declaration? Did you maybe mean to say
instance (Eq a) => PartOrd [a]? If you really meant to sayinstance (Eq a) => PartOrd a, you will need to turn on theFlexibleInstances(and maybe something more too...) in GHC. (However, it doesn't really make sense to haveinstance (Eq a) => PartOrd a.)Finally, where do the function
biggerandsmallercome from? You can't use them inclass (Eq a) => PartOrd a, sinceais a general type. You would need functionsbigger, smaller :: a -> a -> a, in which case you wouldn't even really need thePartOrdclass.