[Haskell-beginners] list monad question
daniel.is.fischer at web.de
Fri Oct 30 11:03:37 EDT 2009
Am Freitag 30 Oktober 2009 14:32:35 schrieb Matthias Guedemann:
> Hi Daniel,
> > That gives
> > combinations n xs = foldr f [] (replicate n xs)
> > pointfree, for extra goodness:
> > -- pointfree f inline
> > combinations n xs = foldr ((. (. (:)) . flip map) . (>>=)) []
> > (replicate n xs) -- eliminate xs
> > combinations n = foldr ((. (. (:)) . flip map) . (>>=)) [] . replicate
> > n -- completely pointfree
> > combinations = (foldr ((. (. (:)) . flip map) . (>>=)) [] .) .
> > replicate
> thank you, looks rather strange to me but works well.
Yes :D The pointfree f is nicely obfuscated. But if your friend is a perl coder, he should
be able to appreciate that.
The standard way to express f, however, is liftM2 (:), so
combinations = (foldr (liftM2 (:)) [] .) . replicate
-- isn't that boring?
But earnestly, replicateM is the thing to use.
More information about the Beginners