[Haskell-beginners] 'Simple' function

Mike Houghton mike_k_houghton at yahoo.co.uk
Wed Jun 10 16:35:05 UTC 2015


Hi,

I’ve been tryimg to write a function  with signature

asString :: IO String -> String


Does someone please have the patience to explain to me what the compiler error messages really mean for these two attempts and exactly what I’m doing (!!!)
If I *do not* give this function any type signature then it works i.e..

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 ?


Another naive attempt is 
asString ioStr = str where  
    str <- ioStr

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


Many Thanks 

Mike



More information about the Beginners mailing list