[Haskell] Real life examples
Benjamin.Rudiak-Gould at cl.cam.ac.uk
Wed Nov 24 18:38:42 EST 2004
John Meacham wrote:
>With my mdo proposal, and I think all proposals brought forth, the
>module system behaves identically to how it normally does for
>namespace control. [...] modules do not change code at all, they
>are pure syntantic sugar for deciding what names you can see.
I'm not sure I understand your mdo proposal correctly then. A lot of
this debate has been over what should happen when a module has a
top-level action like
x <- putStrLn "hello"
Everyone agrees that "hello" should be printed at most once, and that if
the value of x is ever demanded, it should be printed exactly once. But
there's disagreement on everything else. What if I import the module
containing the above declaration, but it can be proven statically that
the value of x will never be demanded? What if it can't be proven
statically, but it happens to be true on a particular run? If "hello" is
printed even when x's value is not demanded, then import does more than
bring names into scope: it also sometimes adds things to the top-level
mdo. If "hello" is printed only when x's value is demanded, then import
is okay but the <- construct is unsafe (though safer than unsafePerformIO).
This kind of thing turned a lot of people off to the idea of top-level
initialization actions. George Russell's proposal is appealing because
it neatly avoids such problems.
More information about the Haskell