bstpierre
bstpierre

Reputation: 31256

haskell: 99 questions #7: heterogeneous list

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...)

Upvotes: 2

Views: 429

Answers (1)

kennytm
kennytm

Reputation: 523764

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

data ListType a = Elem a | List [ListType a]

Upvotes: 8

Related Questions