[Haskell] Re: Top-level <-

John Meacham john at repetae.net
Thu Nov 25 04:55:20 EST 2004


On Thu, Nov 25, 2004 at 10:07:20AM +0100, George Russell wrote:
> John Meacham wrote:
> > Now, my mdo proposal as written would have "hello" outputed exactly once
> > at module start up time no matter what, whether x is demanded or not. it
> > is equivalant to a program transformation that collects all the top
> > level initializers and declarations, puts them all in a mdo block and
> > runs it with the semantics explained in the fixIO paper. (with a
> > deterministic, but partially undefined order)
> 
> What happens if you write the following?
> 
>    y <- f
>    x <- ....
>    let f = something depending on x
> 
> Will it know to evaluate x before y, or is this not allowed?
> 
> What about if the assignments to y and x occur in different modules?  Will 
> the
> RTS have to analyse the dependencies to work out which order to run the 
> assignments
> in?`

No. The semantics are completly and precicely defined by the fixIO
paper. there is a simple desugaring to haskell which I gave in my
original proposal. The basic gist is that things occur almost*
identically to if everything were simply placed in a single mdo block. 
no dependency analysis or strange translation beyond the normal haskell
desugaring mechanisms is required.

recursive top level declarations are no more tricky than are normal
recursive lets. Yes it is possible to write divergent statements, in the same way it
is possible to say

bottom = bottom
you can also say
bottom' <- return bottom' 

(these are actually equivalant.)


Remember, that unlike normal monadic binding, this is using recursive
monadic binding, meaning the results of future computations can be used
as long as they arn't strictly evaluated, in the same way you can write
mutually recursive variables but if both are strict in each other they
will diverge :). The fact that everyone seems to get along fine despite
the ability to write divergent computations with recursive lets makes me
think this won't be too much for anyone to handle. 


        John


* The differences, which I elaborated on earlier are due to a
  monomorphic restriction on user-written 'mdo' let-bound variables which is
  irrelevant to the desugaring so the translation from mdo -> haskell
  expression is slightly different than presented in the paper. 


-- 
John Meacham - ⑆repetae.net⑆john⑈ 


More information about the Haskell mailing list