<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 10, 2015 at 12:35 PM, Mike Houghton <span dir="ltr"><<a href="mailto:mike_k_houghton@yahoo.co.uk" target="_blank">mike_k_houghton@yahoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div id=":zr" class="" style="overflow:hidden">asString ioStr = do<br>
    str <- ioStr<br>
    return $ str<br>
<br>
and the compiler tells me its signature is<br>
<br>
asString :: forall (m :: * -> *) b. Monad m => m b -> m b<br>
<br>
which, at this stage of my Haskell progress, is just pure Voodoo.<br>
Why isn’t it’s signature  asString :: IO String -> String ?<br></div></blockquote></div><br>Because the only thing it knows about ioStr is that it is a monadic action. IO is not the only monad, nor even the only useful monad. And "do" syntax including <- is not specific to IO.</div><div class="gmail_extra"><br></div><div class="gmail_extra">That said, most of the type signature it showed you is only important if you are doing advanced things like type level programming. The short version of that type signature is</div><div class="gmail_extra"><br></div><div class="gmail_extra">    asString :: Monad m -> m b -> m b<br><br clear="all"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-size:12px">asString ioStr = str where</span><br style="font-size:12px"><span style="font-size:12px">    str <- ioStr</span><br style="font-size:12px"><br style="font-size:12px"><span style="font-size:12px">and then compiler says</span><br style="font-size:12px"><span style="font-size:12px">parse error on input ‘<-’</span><br style="font-size:12px"></blockquote><div class="gmail_extra"><br></div><div class="gmail_extra"><- is part of "do" syntax, it cannot be used by itself like that.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Just to give you some idea of what's really going on, let me show you that first one without the "do" syntax:</div><div class="gmail_extra"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">asString ioStr = ioStr >>= (\s -> return $ s)</blockquote><div><br></div><div>(Let me additionally note that the "$" does nothing whatsoever in either case, and can and should be left out. Moreover, (x >>= \y -> return y) is just a long-winded way of writing (x).) </div><div class="gmail_extra"><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>                                  <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div><div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div></div>
</div></div>