[Haskell-beginners] list monad question
Matthias Guedemann
matthias.guedemann at ovgu.de
Fri Oct 30 08:37:55 EDT 2009
Thanks David,
> all3 ls = do
> a <- ls
> b <- ls
> c <- ls
> return (a,b,c)
>
> For each element a of list ls , for each element b of the same list
> ls, and for each element c of the same list ls, make a tuple of them.
> return the list of tall the tuples.
But it is a bit more complicated. I changed the result to [a,b,c] in order to
have variable length results. I am now trying to get a
"allN ls n" function that returns the result for the original problem with
"allN [0..5] 3" and all combinations of the form [a,b] with "allN [0..5] 2".
So basically I want a variable number of name bindings in the list
comprehension. Is this possible in a (simple) way using the list monad? Maybe
like
allN ls n = foldr (>>=) [] (replicate n ls) >>= return
regards,
Matthias
--
__________________________________________________________
___ __ __
Dipl. Inf. Matthias Guedemann / __\/ _\ /__\
Computer Systems in Engineering / / \ \ /_\
Otto-von-Guericke Universitaet Magdeburg / /___ _\ \//__
Tel.: 0391 / 67-19359 \____/ \__/\__/
__________________________________________________________
More information about the Beginners
mailing list