[Haskell-cafe] Re: A simple beginner question

Achim Schneider barsoap at web.de
Tue Jun 3 20:51:09 EDT 2008


Adam Smyczek <adam.smyczek at gmail.com> wrote:

> data SampleType = A | B Int | C String | D -- .... etc.
	deriving (Eq)

> sampleTypes = [A, B 5, C "test"] :: [SampleType]
> 

If you derive from Eq, you can do

isA = (==) A

filter isA sampleTypes

or ad-hoc:
filter ((==) A) sampleTypes

things like 
filter (\x -> case x of 
	{ A -> True
	; B b | b > 2 -> True
	; C c | c == "foo" -> True
	; _ -> False}) sampleTypes
work, too. Admittedly, I'm lambda-spoilt.

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 



More information about the Haskell-Cafe mailing list