I am preparing for test in haskell and I found a task from last test where was given to generate infinite list lists.
generate :: Num n => n -> [[n]]
where list is n-tuple, n is from parameter.
moreover the lists has to be sorted.
For exaple:
generate 2 = [[0,0],[0,1],[1,0],[1,1],[0,2],[1,2],[2,0],[2,1],[2,2],[0,3],....]
I have to use only basic functions.
I know that it surely is simple, but I dont know how to do it and I also can't find it on the internet.
I will be really glad for any help.
type tup = (X, tup). GHC rejects such infinite types.[[n]]is the type of a list, which can indeed be infinite (but only at runtime; it's perfectly finite to the type checker).Numis an overly broad constraint; you can't have a list of length 1.5 (or a 1.5-tuple).n -> [[n]]. Also,Int n => ...is not Haskell, unlessIntis a custom class -- was thatNum n => ...instead?generate k = concatMap (allTuplesWithMaxElem k) [0..]?