A problem about Haskell 99 questions

In problem 7 http://www.haskell.org/haskellwiki/99_questions/1_to_10, the example in haskell is below: *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 [])[]
What are the functions List and Elem? I cann't hoogle it.

On Tue, 2011-05-17 at 17:51 +0800, amazingjxq wrote:
In problem 7, the example in haskell is below:
*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 []) [] What are the functions List and Elem? I cann't hoogle it.
Those would be type constructors for the aforementioned "nested list structure." I'm not sure if defining that type is part of the problem, so I won't give it away!

On Tuesday 17 May 2011 11:51:24, amazingjxq wrote:
In problem 7 http://www.haskell.org/haskellwiki/99_questions/1_to_10, the example in haskell is below:
*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 []) []
What are the functions List and Elem? I cann't hoogle it.
They're the constructors of a datatype defined specifically for this problem. While in Lisp, you can put different types of things in the same list, Haskell lists are homogeneous (every element has the same type). So to create nested lists, you have to create a type T that can hold lists of type T, like data NestedList a = Elem a | List [NestedList a] (and if you follow the 'Solutions' link at the problem, you find the source where this is defined).
participants (3)
-
amazingjxq
-
Arlen Cuss
-
Daniel Fischer