[Haskell-beginners] list monad question
Matthias Guedemann
matthias.guedemann at ovgu.de
Fri Oct 30 08:56:40 EDT 2009
> How about a recursive function like this:
>
> alln 1 ls = map (:[]) ls
> alln n ls = do
> a <- ls
> as <- alln (n-1) ls
> return (a:as)
>
> Note that `ls :: [t]` and `all (n-1) ls :: [[t]]` has different types but
> it's okay because both are in the list monad.
>
> Also, it can be done with list comprehensions:
>
> alln' 1 ls = [[a] | a<-ls]
> alln' n ls = [a:as | a<-ls, as<-alln' (n-1) ls]
Works great, thanks a lot
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