tags:

views:

121

answers:

1

I'm learning haskell. Currently working through 99 questions, a little bit stuck on #7:

Problem 7 (**) Flatten a nested list structure.

Transform a list, possibly holding lists as elements into a `flat' list by replacing each list with its elements (recursively).

Example in Haskell:

*Main> flatten (Elem 5)
[5]
*Main> flatten (List [Elem 1, List [Elem 2, List [Elem 3, Elem 4], Elem 5]])
[1,2,3,4,5]
*Main> flatten (List [])
[]

Where do Elem and List come from? What do I have to do to be able to use them in my program? (Or does the question assume that I have to define a new type for these -- if that's the answer I'll go off and reread that section of the tutorial...)

+7  A: 

Those are just constructor of some types, e.g.

data ListType a = Elem a | List [ListType a]
KennyTM
Note that ListType is a really bad name. It's actually a tree.
Martijn