[Haskell-begin] data declarations
rogermyers at ymail.com
Tue Jul 22 23:01:23 EDT 2008
Not sure if I'm on the right track here, so as a beginner I thought I'd ask on
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
data All = Tinteger Int
| Tbool Bool
| Tstring String
| Tarray [Alltypes]
data Simple = Tinteger
data Composite = Tstring
data Mixed = Simple
k :: All -> [Mixed]
k a = case a of
Simple s -> [Simple s]
Composite c -> [Composite c]
But this isn't valid Haskell code because I can't have multiple declarations of
the same types, is there a way to specify a relationship, if so can someone
point me in the right direction?
More information about the Beginners