[Haskell-cafe] matching constructors

Vadim Zaliva lord at crocodile.org
Fri Mar 5 10:56:15 EST 2004


Hi!

I am new to Haskell, but I have background in various programming 
languages (including Lisp)

I have very basic question, if there is a way to match algebraic types 
constructors besides
use of pattern matching. I wrote today code like this:

data Flag = Verbose |
             Input String  |
             Output String |
             Filter String
             deriving Show

instance Eq Flag where
     Verbose  == Verbose  = True
     Input  _ == Input  _ = True
     Output _ == Output _ = True
     Filter _ == Filter _ = True
     _ == _ = False

findFlag :: Flag -> [Flag] -> Flag
findFlag f [] = f
findFlag y (x:xs) = if x == y then x else findFlag y xs

If there is a cleaner way to implement findFlag and Eq Flag?

Vadim

--
"La perfection est atteinte non quand il ne reste rien a ajouter, mais
quand il ne reste rien a enlever."  (Antoine de Saint-Exupery)



More information about the Haskell-Cafe mailing list