[Haskell-cafe] help with some code. it doesn't whant to compile.
Jules Bean
jules at jellybean.co.uk
Tue Feb 8 03:11:49 EST 2005
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
More information about the Haskell-Cafe
mailing list