[Haskell-cafe] Execution order in IO

Sylvain Henry hsyl20 at gmail.com
Wed Apr 15 09:46:40 UTC 2015


Hi,

You can consider that:
type IO a = World -> (World, a)
Where World is the state of the impure world.

So when you have:
getLine :: IO String
putStrLn :: String -> IO ()

Is is in fact:
getLine :: World -> (World, String)
putStrLn :: String -> World -> (World, ())

You can compose IO actions with:
(>>=) :: IO a -> (a -> IO b) -> IO b
(>>=) :: (World -> (World,a)) -> (a -> World -> (World,b)) -> World ->
(World,b)
(>>=) f g w = let (w2,a) = f w in g a w2

do-notation is just syntactic sugar for this operator.

So there is an implicit dependency between both IO functions: the state of
the World (which obviously doesn't appear in the compiled code).

Sylvain


2015-04-15 11:07 GMT+02:00 Jon Schneider <haskell at jschneider.net>:

> Good morning all,
>
> I think I've got the hang of the way state is carried and fancy operators
> work in monads but still have a major sticky issue.
>
> With lazy evaluation where is it written that if you write things with no
> dependencies with a "do" things will be done in order ? Or isn't it ?
>
> Is it a feature of the language we're supposed to accept ?
>
> Is it something in the implementation of IO ?
>
> Is the do keyword more than just a syntactic sugar for a string of binds
> and lambdas ?
>
> Jon
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150415/5d51a3b4/attachment.html>


More information about the Haskell-Cafe mailing list