[Haskell-begin] data declarations

Bas van Dijk v.dijk.bas at gmail.com
Wed Jul 23 03:15:16 EDT 2008


On Wed, Jul 23, 2008 at 5:42 AM, Jeff Zaroyko <jeffzaroyko at gmail.com> wrote:
> data Simple = Tinteger Int
>            | Tbool Bool
> data Composite = Tstring String
>               | Tarray [All]
>
> data All = Simple | Composite

Don't you mean:

data All = Simple Simple | Composite Composite

So the 'All' type contains the 'Simple' and 'Composite' types. In case
you find it confusing that the constructor names are the same as the
names of the types you can write something like:

data All = S Simple | C Composite

I don't know what your 'k' should do. Because your function...

> k :: All -> [All]
> k a = case a of
>        Simple -> [a]
>        Composite -> [a]

...can be simplified to: 'k a = [a]'  (if you disregard the strictness
properties)

which isn't very useful. So I guess you mean something different.

regards,

Bas


More information about the Beginners mailing list