<p dir="ltr">Nitpick: (&) is flipped function application ($), not composition (.) -- though the signature you gave was correct.</p>
<div class="gmail_quote">On Jun 11, 2016 11:07 PM, "Csongor Kiss" <<a href="mailto:kiss.csongor.kiss@gmail.com">kiss.csongor.kiss@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">Hi,</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">(>>=) :: Monad m => m a -> (a -> m b) -> m b, and if I understand correctly, what you need is a ‘generic’ version, that works without the returns?</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">'return :: a -> m a' for some monad m. This m comes from the monad instance you use, but if we want a generic one, it’s only possible by fixing a specific m. The obvious choice is to use the Identity monad and have a specialised (>>=‘) :: Identity a -> (a -> Identity b) -> Identity b.</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">For all `a`, `Identity a` is isomorphic to `a`, so with a bit of cheating, you could rewrite the above to (>>=‘’) :: a -> (a -> b) -> b,</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">which starts to look really familiar, in fact, it’s just the function composition (.) with its arguments flipped, and is actually defined</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">as (&) in Data.Function.</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><span style="font-family:'helvetica Neue',helvetica">g' = 2 & \n -> (n + 1) & \n -> (n + 3)</span></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><span style="font-family:'helvetica Neue',helvetica"><br></span></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><span style="font-family:'helvetica Neue',helvetica">This was obviously a really roundabout way of arriving at the result, but I think the analogy with function composition is really nice, as we can think of (a -> b) as a special case of (a -> m b), the so-called Kleisli arrow. What monads do is they compose these Kleisli arrows.</span></div> <br> <div><div style="font-family:helvetica,arial;font-size:13px">-- <br>Csongor<br></div></div><p>On 12 June 2016 at 06:47:13, Christopher Howard (<a href="mailto:ch.howard@zoho.com" target="_blank">ch.howard@zoho.com</a>) wrote:</p> <blockquote type="cite"><span><div><div></div><div>Hi, I am learning about monads, and this question came to mind: is there
<br>a way to have a sequence of functions left to right like so:
<br>
<br>g = return 2 >>= \n -> return (n + 1) >>= \n -> return (n + 3)
<br>
<br>Either: some kind of generic monad that makes this legal, or some way to
<br>do this without monad (i.e., without the "returns").
<br>
<br>--  
<br><a href="http://justonemoremathproblem.com" target="_blank">http://justonemoremathproblem.com</a>
<br>To protect my privacy, please use PGP encryption. It's free and easy
<br>to use! My public key ID is 0x340EA95A (<a href="http://pgp.mit.edu" target="_blank">pgp.mit.edu</a>).
<br>
<br>_______________________________________________
<br>Haskell-Cafe mailing list
<br><a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a>
<br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a>
<br></div></div></span></blockquote></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div>