<div dir="ltr"><div><div><div><div><div><div>If you type :i Monad in ghci, you will see this instance<br><br>instance Monad ((->) r)<br><br></div>What this means is a function where the first argument is of type 'r'... is a monad. You can in fact use do notation / return on a tuple to manipulate its second argument monadically.<br><br>So let's look at what that does to the type signature of join when 'm' is ((->) b)<br><br></div><div>join :: Monad m => m (m a) -> m a<br><br> -- m = ((->) b)<br><br></div><div>join :: ((->) b ((->) b a)) -> (((->) b a))<br><br>Now we just have to move the arrows from prefix to infix. Let's do it step by step.<br><br>join :: ((->) b (b -> a)) -> (b -> a)<br>join :: (b -> (b -> a)) -> (b -> a)<br><br></div><div>x -> (y -> z) is equivalent to x -> y -> z<br></div><div><br>join :: (b -> b -> a) -> (b -> a)<br>join :: (b -> b -> a) -> b -> a<br><br></div><div>So now when you put an operator into it that takes two arguments<br><br></div><div>(,) :: a -> b -> (a,b)<br><br></div><div>You get the type you saw.<br></div><div><br></div><div>join (,) :: b -> (b, b)<br></div><div><br></div></div></div></div></div><br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 8, 2017 at 10:37 AM, Quentin Liu <span dir="ltr"><<a href="mailto:quentin.liu.0415@gmail.com" target="_blank">quentin.liu.0415@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif">Hi,
<div><br></div>
<div>The function `join` flattens a double-layered monad into one layer and its type signature is </div>
<div><br></div>
<div> join :: (Monad m) => m (m a) -> m a</div>
<div><br></div>
<div>But when the first argument supplied is `(,)`, the type signature becomes </div>
<div><br></div>
<div> join (,) :: b -> (b, b)</div>
<div><br></div>
<div>in ghci. The monad constraint is lost when supplied the first argument. So my question is why the type constraint is lost and what monad is supplied here.</div>
</div>
<div name="messageSignatureSection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif"><br>
Regards,
<div>Qingbo Liu</div>
</div>
</div>
<br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>