
Hello Ertugrul, this looks interesting. I read Brent Yorgeys Typeclassopedia and also the work you cite in your tutorial. So I am trying to learn about Applicative, Monoids, Monads etc. by using them. Your description of the library functions comes handy, as reading the source directly does not really help if you're still struggling with understanding the concepts. And on the other hand, due to the abstract nature of monads, a lot of functionality should be "hidden" in the library (just like my rewrite of replicateM) thank you very much, will read it on the weekend regards Matthias Excerpts from Ertugrul Soeylemez's message of Fr Okt 30 15:01:29 +0100 2009:
Hello Matthias,
you may want to have a look at section 11 of my monads tutorial [1], which contains monadic library functions like replicateM together with examples and detailed explanations.
[1] http://ertes.de/articles/monads.html#section-11
Greets, Ertugrul.
Matthias Guedemann
wrote: Hi,
a friend of mine wanted to write function (in Perl) that creates all tuples of length 3 of the elements of a given list, e.g. [(0,0,0),(0,0,1),(0,0,2),...,(5,5,5)] for the list [0..5]. Trying to get better at Haskell, I wrote a small function using the list monad for this (tuples replaced with lists)
all3 ls = do a <- ls b <- ls c <- ls return [a,b,c]
Now I want to make it capable to create all combinations of length n instead of fixed length 3 (that's why list instead of tuple), but I don't really see how. As the do notation translates to
ls >>= \a -> etc.
I thought it should be possible to have some sort of "foldr (>>=)" over a list of length n, but I can't figure out how to collect the variable number of results in a list for the "return".
Any hints for that?
best regards Matthias
-- __________________________________________________________ ___ __ __ Dipl. Inf. Matthias Guedemann / __\/ _\ /__\ Computer Systems in Engineering / / \ \ /_\ Otto-von-Guericke Universitaet Magdeburg / /___ _\ \//__ Tel.: 0391 / 67-19359 \____/ \__/\__/ __________________________________________________________