[Haskell] help with some basic code that doesn't work

pablo daniel rey listas at pablodanielrey.com.ar
Mon Feb 7 15:36:55 EST 2005


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
data Dir = Left | Right | Up | Down
data Piece = Vertical | Horizontal | CodeA | CodeB

flow = [(Horizontal, Left, Left),
     (Horizontal, Right, Right),
     (Vertical, Down, Down),
     (Vertical, Up, Up), ................ etc ]


fst :: (a,b,c) -> a
fst (x,y,z) = x

scnd :: (a,b,c) -> b
scnd (x,y,z) = y

third :: (a,b,c) -> c
third (x,y,z) = z

element :: [(Piece, Dir, Dir)] -> Maybe Dir
element [] = Nothing
element xs = Just (third (head xs))

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

i don't know what's happening.
help!!!
thanks in advance


More information about the Haskell mailing list