Reputation: 13
So basically I have:
numList = [0,1..]
numList' = take 2 numList
listsList = [] : [new : old | old <- listsList, new <- numList'] -- list of all possible binary numbers (infinite)
listsList' = take 10000 listsList -- just to not stuck because of infinite list
finalList n = [ x | x <- listsList', length x == n] -- taking n-sized lists
and it is working (even if I change 2 to a different number in the second line) but I need last function to have two arguments like this:
finalList n k
where k should be given to the numList' to be something like
numList' = take k numList
I also can not make
numList' k = take k numList
because then the function listsList do not work. How can I solve this?
Upvotes: 0
Views: 86
Reputation: 531165
numList'
isn't a function; it's simply the list resulting from a call to take
. As such, you can't pass a different argument to it; the function has already been called. The simplest thing to do is define a function digits
that takes k
as an argument and returns the desired subset of integers.
digits k = [0..k-1]
listsList k = [] : [new : old | old <- listsList k, new <- digits k] -- list of all possible binary numbers (infinite)
listsList' k = take 10000 $ listsList k -- just to not stuck because of infinite list
finalList n k = [ x | x <- listsList' k, length x == n] -- taking n-sized lists
Upvotes: 2