Changes between Version 2 and Version 3 of Ticket #9390, comment 12


Ignore:
Timestamp:
Aug 6, 2014 11:50:55 AM (5 years ago)
Author:
simonpj
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #9390, comment 12

    v2 v3  
     1(Retrospectively edited to remove incorrect stuff!)
     2
    13My comment meant that the `x` thunk will reliably be evaluated only after performing the `write A` side effect. 
    24
    3 The question of whether it is performed before the freeze is quite a separate one.  Yes it will, because the `seq` ensures that (in effect) there is a data dependency between `x` and `(V.freeze vm >>= print)`, so we can't perform the latter action until we have evaluated `x`.  If instead of {{{x `seq` (V.freeze vm >> print)}}} we'd written
    4 {{{
    5   if x>0 then V.freeze vm >> print
    6          else print "hello"
    7 }}}
    8 it would be totally clear that you couldn't do the freeze until `x` was evaluated.  And `seq` behaves like that.
     5The question of whether it is performed before the freeze is quite a separate one.  Yes it will, because the `seq` ensures that (in effect) there is a data dependency between `x` and `(V.freeze vm >>= print)`, so we can't perform the latter action until we have evaluated `x`. 
    96
    107To put it another way, if you write
    118{{{
    12 a `seq` b `seq` blah
     9a `seq` blah
    1310}}}
    14 then GHC won't guarantee the order in which `a` and `b` will be evaluated.  But we ''do'' guarantee that both `a` and `b` will have been evaluated before the value of `blah` is returned.
     11then GHC won't guarantee the order in which `a` and `blah` will be evaluated.  But we ''do'' guarantee that both `a` and `blah` will have been evaluated before the value of `blah` is returned.  (But we do not guaranteed that `a` is evaluated before the evaluation of `blah` is ''begun''.)
     12
     13So if you have {{{(a `seq` b `seq` blah)}}}, then you know that `a`, `b`, and `blah` will all evaluated before the value is returned.
    1514
    1615Does that make it clearer?