[Haskell-begin] data declarations
Jeff Zaroyko
jeffzaroyko at gmail.com
Tue Jul 22 23:42:32 EDT 2008
Brandon S. Allbery KF8NH <allbery <at> ece.cmu.edu> writes:
>
>
> On 2008 Jul 22, at 23:01, Roger Myers wrote:
>
> > Not sure if I'm on the right track here, so as a beginner I thought
> > I'd ask on
> > this list.
> >
> > I want to declare a type 'All' that consists of the of the types
> > 'Tinteger,
> > Tbool, Tstring, Tarray' but I would also like to make a relationship
> > that
> > Tinteger and Tbool are also the type 'Simple' and that 'Tstring' and
> > 'Tarray'
> > are 'Composite' and that Mixed is then either Simpletype or Composite.
> >
> > So I can then write a function that takes a type of All and produces
> > a list of
> > Mixed.
>
> Any particular reason that All can't be represented by Mixed? That
> would be my first cut at it (assuming I didn't need advanced type
> hackery for some reason).
>
Hmm... ah, bad thinking on my part. I think this serves me a lot better:
data Simple = Tinteger Int
| Tbool Bool
data Composite = Tstring String
| Tarray [All]
data All = Simple | Composite
k :: All -> [All]
k a = case a of
Simple -> [a]
Composite -> [a]
Thanks :)
More information about the Beginners
mailing list