[Haskell-cafe] Execution order in IO

Niklas Haas haskell at nand.wakku.to
Wed Apr 15 15:41:38 UTC 2015


On Wed, 15 Apr 2015 17:34:50 +0200, Marcin Mrotek <marcin.jan.mrotek at gmail.com> wrote:
> Changing it to, let's say
> 
> main = do
>  a <- getLine
>  b <- getLine
>  c <- foo a b
> 
> makes it obvious there's no way to evaluate c before a and b, whatever
> monad that would be, as foo may c can change the shape of the monad
> anyway it pleases.

import Debug.Trace

foo _ _ = return ()

main = do
  a <- trace "a" <$> getLine
  b <- trace "b" <$> getLine
  c <- trace "c" <$> foo a b
  print c

Running this program:

first input
second input
c
()

So as you can see, ‘a’ and ‘b’ never get evaluated.


More information about the Haskell-Cafe mailing list