[Haskell] threading mutable state through callbacks

Simon Marlow simonmar at microsoft.com
Wed Oct 13 10:34:07 EDT 2004


On 13 October 2004 03:36, Wolfgang Thaller wrote:

> b) Some predetermined order, with semantics like mdo:
> 
> John Meacham wrote:
> 
>> The basic idea is that your entire program behaves as if in a giant
>> 'mdo' block, ordered in module dependency order.

I also like the mdo idea - in fact it occurred to me yesterday, but I
wasn't sure whether there would be any gotchas when the details were
worked out, and it looks like John has established that things work out
nicely.

GHC already has an initialisation procedure for each module in the
program which could be adapted to run the initialisation-time IO
actions, with a little effort.

I'm more worried about what other changes we have to make to the
compiler: if we can avoid having to flag top-level bindings as
monadic/non-monadic all the way through the compiler, then we could
avoid a pervasive change to the compiler.  At the moment I can't see an
obvious way to do that.

> What is module dependency order? There's no such thing when there are
> circular dependencies, and when there aren't any, it might still
> depend on the order of import directives, which is probably not
> something I want program semantics to depend on.
> I feel that In a large program, you'll probably get more surprises
> from this.
> The good thing is that you can always use unsafeInterleaveIO to get
> the other semantics back, so we should probably investigate this
> further. 

GHC's init blocks are run in dependency order, picking an arbitrary
depth-first traversal when there's a recursive module dependency.  Seems
as good a choice as any.

Cheers,
	Simon


More information about the Haskell mailing list