Re: [Haskell-cafe] A simple beginner question

2008-06-04 Thread Yitzchak Gale
Adam Smyczek wrote: 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? There have been many useful replies. But since Adam originally announced that this is a beginner question, I

[Haskell-cafe] A simple beginner question

2008-06-03 Thread Adam Smyczek
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? It

Re: [Haskell-cafe] A simple beginner question

2008-06-03 Thread Philip Weaver
On Tue, Jun 3, 2008 at 5:11 PM, Adam Smyczek [EMAIL PROTECTED] 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 -

Re: [Haskell-cafe] A simple beginner question

2008-06-03 Thread Ronald Guida
Adam Smyczek wrote: 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? Here's one way to do it: filter (\x - case x of A - True; otherwise - False) sampleTypes == [A] filter

Re: [Haskell-cafe] A simple beginner question

2008-06-03 Thread Dan Weston
There's always one more way to do things in Haskell! :) Here's yet another way to get at the payloads in a list. You don't have to know how this works to use it: data SampleType = A | B Int | C String unA :: SampleType - [()] unA A = return () unA _ = fail Not an A unB :: SampleType

Re: [Haskell-cafe] A simple beginner question

2008-06-03 Thread Don Stewart
adam.smyczek: 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

Re: [Haskell-cafe] A simple beginner question

2008-06-03 Thread Luke Palmer
On Tue, Jun 3, 2008 at 6:48 PM, Ronald Guida [EMAIL PROTECTED] wrote: filter (\x - case x of A - True; otherwise - False) sampleTypes == [A] filter (\x - case x of B _ - True; otherwise - False) sampleTypes == [B 5] There's a neat little mini-trick for these types of pattern matches: