
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.