[Haskell-cafe] matching constructors

Vadim Zaliva lord at crocodile.org
Mon Mar 8 14:41:31 EST 2004

On Mar 8, 2004, at 12:55, Ben Rudiak-Gould wrote:

This would work, but I will have to write [] part for each option.
Generics approach is overkill but looks much neater when used.
But thanks for suggestion anyway, it is always good to learn yet
another way of doing things.


> Try this instead:
> 	doSomething $ option "none" [fltflag | Filter fltflag <- opts]
> 	option :: a -> [a] -> a
> 	option def []  = def
> 	option def [x] = x
> 	option def _   = error "Only one of each option allowed"

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2388 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20040308/6c175d40/smime.bin

More information about the Haskell-Cafe mailing list