I believe that you want to be a replicateM
function in Control.Monad
.
The list monad is based on the "attempt of all possible combinations", and regular replicate
creates the list by repeating the item several times. Thus, the result of replicateM
is, given some list of possible values, a list of all possible ways to select an item from this list several times.
For example:
> replicateM 2 [0, 1] [[0,0],[0,1],[1,0],[1,1]] > replicateM 3 [0, 1] [[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]]
So, to extend your function to arbitrary repetitions, you should use something like:
getListN nx = replicateM n [1..x]
... where your original getList
will be equivalent to getListN 3
.