[Haskell-cafe] A simple beginner question

Philip Weaver philip.weaver at gmail.com
Tue Jun 3 20:48:24 EDT 2008


On Tue, Jun 3, 2008 at 5:11 PM, Adam Smyczek <adam.smyczek at gmail.com> wrote:
> Example:
>
> data SampleType = A | B Int | C String | D -- .... etc.
>
> sampleTypes = [A, B 5, C "test"] :: [SampleType]
>
> How do I find for example element A in the sampleTypes list?
> Do I have to create e.g.:
>
> isA :: SampleType -> Bool
> isA A = True
> isA _ = False
>
> for every constructor and use find?

isA is already defined for every constructor, so all you have to do is
"find isA"

> It feels like this is not the quicker method.
>
> Thanks,
> Adam
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list