
Hi all, This is my first post to this list. Nice to meet you! I study Functional Programming with Haskell, and I have stuck at p.77 (the first checkpoint in FP, as far as I understand). Passing this, I feel that I make steps towards understanding monadic binding! So I would like to ask about whether or not this: P1>>=λu1 -> P2>>=λu2 -> P3>>=λu3 -> P4>>=λu4 -> return (f u1 u2 u3 u4) can be rewritten to: P1>>=(λu1 -> P2>>=(λu2 -> P3>>=(λu3 -> P4>>=(λu4 -> return (f u1 u2 u3 u4))))) I am trying to understand what is the f in p>>=f in each one of above sequencing applications? So >>= gets you in this structure (is this the monad?), and return is the gate out of it? Best regards. These are my first steps to FP! -- Angelos Bimpoudis Doctoral Researcher, Pervasive Computing [p-comp.di.uoa.gr] SDE, Nessos IT S.A. [www.nessos.gr] (m): +306942075153 http://gr.linkedin.com/in/aggelosmp Description: Description: Linkedin http://www.facebook.com/aggelosmp Description: Description: Facebook http://www.studentguru.gr/blogs/grnemo/ Description: Description: Blog RSS http://twitter.com/aggelosmp Description: Description: Twitter

Someone else can probably explain this better than I, but... "return" takes a value and puts it in a minimal context that still yields that value. I think of "return" as saying "take this ordinary value and make a monadic value out of it, in the most straightforward way possible". Consider the Maybe monad, for example. What kind of value would you expect the expresion "return 7" to create? Well, there are only two constructors for Maybe values, Just ___ and Nothing. The latter wouldn't do any good, because it doesn't encapsulate the value "7" in any way. So the only choice is "Just 7".
= is like function application, only instead of taking a normal value and feeding it to a normal function, it takes a monadic value and feeds it to a function that takes a normal value but returns a monadic value. It provides a convenient notation for chaining a series of monadic computations together.

2010/12/2 Angelos Bimpoudis
P1>>=λu1 ->
P2>>=λu2 ->
P3>>=λu3 ->
P4>>=λu4 ->
return (f u1 u2 u3 u4)
can be rewritten to:
P1>>=(λu1 -> P2>>=(λu2 -> P3>>=(λu3 -> P4>>=(λu4 -> return (f u1 u2 u3 u4)))))
Yes, but the extra parenthesis you added are not necessary. I am trying to understand what is the f in p>>=f in each one of above
sequencing applications?
Amy probably explained it better that I will, and I'm not sure I understood the question but : In P1>>=(λu1 -> P2>>=(λu2 -> P3>>=(λu3 -> P4>>=(λu4 -> return (f u1 u2 u3 u4))))) -- ------------------------------------------------------------------------- p f In P2>>=(λu2 -> P3>>=(λu3 -> P4>>=(λu4 -> return (f u1 u2 u3 u4))))) -- ------------------------------------------------------------ p f Etc.
So >>= gets you in this structure (is this the monad?), and return is the gate out of it?
(Someone please correct me if I'm not using the right words;)
= binds two monadic computation together, getting a value out of the first one, and feeding that value to the second one. return is more a gate into it, as it takes a value and 'returns' its monadic equivalent, for example :
-- In the list monad Prelude> return 1 :: [Int] [1] As you see, return didn't "gate out" anything of the list monad, on the contrary it took a value into the list monad. Same with the Maybe monad : Prelude> return 1 :: Maybe Int Just 1 And it works that way for every monad, returns take a value, and return its monadic version. Best regards David.

On Thu, 02 Dec 2010 23:50:16 +0100, Angelos Bimpoudis
I am trying to understand what is the f in p>>=f in each one of above sequencing applications?
Maybe "A tour of the Haskell Monad functions" can help: http://members.chello.nl/hjgtuyl/tourdemonad.html Regards, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html --

Thank you all for the answers. There is a hell of a trip ahead!
-----Original Message----- From: Henk-Jan van Tuyl [mailto:hjgtuyl@chello.nl] Sent: Friday, December 03, 2010 2:37 PM To: beginners@haskell.org; Angelos Bimpoudis Subject: Re: [Haskell-beginners] Parser composition
On Thu, 02 Dec 2010 23:50:16 +0100, Angelos Bimpoudis
wrote: I am trying to understand what is the f in p>>=f in each one of above sequencing applications?
Maybe "A tour of the Haskell Monad functions" can help: http://members.chello.nl/hjgtuyl/tourdemonad.html
Regards, Henk-Jan van Tuyl
-- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html --
participants (4)
-
Amy de Buitléir
-
Angelos Bimpoudis
-
David Virebayre
-
Henk-Jan van Tuyl