On Wed, Jun 10, 2015 at 12:35 PM, Mike Houghton <mike_k_houghton@yahoo.co.uk> wrote:
asString ioStr = do
    str <- ioStr
    return $ str

and the compiler tells me its signature is

asString :: forall (m :: * -> *) b. Monad m => m b -> m b

which, at this stage of my Haskell progress, is just pure Voodoo.
Why isn’t it’s signature  asString :: IO String -> String ?

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.

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

    asString :: Monad m -> m b -> m b

asString ioStr = str where
    str <- ioStr

and then compiler says
parse error on input ‘<-’

<- is part of "do" syntax, it cannot be used by itself like that.

Just to give you some idea of what's really going on, let me show you that first one without the "do" syntax:

asString ioStr = ioStr >>= (\s -> return $ s)

(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).) 

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net