how to convert IO String to string
Ahn Ki-yung
kyagrd@bawi.org
Sat, 23 Nov 2002 07:49:33 +0900
Ashley Yakeley wrote:
>At 2002-11-22 08:12, Lu Mudong wrote:
>
>
>>what i need is a string,
>>
>>
>
>You can do the conversion with "<-", but only inside a "do" block. For
>instance:
>
> myReadFile :: IO String
> myReadFile = ...
>
> main = do
> s <- myReadFile
> putStrLn s
>
>Here, s has type String.
>
>
'do' is a syntactic sugar of monadic operations.
The original form can be written as
main = myReadFile >>= \s -> putStrLn s
and more short by eta-conversion
main = myReadFile >>= putStrLn