[Haskell-beginners] recursively building lists

Torsten Otto t-otto-news at gmx.de
Tue Dec 8 17:34:30 EST 2009


Hi!

While trying to implement "words", we ran into the question of how to build lists of lists. The trouble boils down to this:

test = []:[]

is no problem, just as

Prelude> []:[]:[]:[]
[[],[],[]]

works fine. Now trying to put the two together _is_ a problem: 

testlist 1 = []:[]
testlist n = []:(testlist n-1)

    No instance for (Num [[a]])
      arising from a use of `testlist' at <interactive>:1:0-9
    Possible fix: add an instance declaration for (Num [[a]])
    In the expression: testlist 2
    In the definition of `it': it = testlist 2

Can someone please explain, what is going on here?

Regards,
Torsten


More information about the Beginners mailing list