
On 7 Feb 2005, at 20:23, pablo daniel rey wrote:
hello i'm new to haskell so i'm sorry if this is a stupid question, but i'm having problems with some basic code. the code :
data Maybe Dir = Just Dir | Nothing
(You don't want this. Maybe already exists as a type in the Prelude, you don't want to redefine it)
data Dir = Left | Right | Up | Down data Piece = Vertical | Horizontal | CodeA | CodeB
[snip]
chgDir :: Piece -> Dir -> Maybe Dir chgDir p d = element (filter (\x -> p == (fst x)) (filter (\x -> d == (scnd x)) flow))
the error i get :
Instances of (Eq Dir, Eq Piece) required for definition of chgDir
The comparision == is not defined on all types, only on types in the type class Eq. You have to provide an Eq instance for Dir and Piece. Fortunately, for simple 'enumerated' types like Dir and Piece you can simply add 'deriving Eq' to the data declarations. Jules