[Haskell-cafe] Re: Yet another IO initializer: Effectful
declarations and an ACIO monad
Ian.Stark at ed.ac.uk
Ian.Stark at ed.ac.uk
Fri Nov 26 10:57:20 EST 2004
On Fri, 26 Nov 2004, Jules Bean wrote:
>
> On 26 Nov 2004, at 12:08, George Russell wrote:
>
>> > Yes, you need to explicitly initialise it; but you don't need then to
>> > pass the initialized handle all around your code. The painful plumbing
>> > goes away.
>> I think this is either unwieldy or inefficient. Imagine a large library
>> containing lots of these things which need to be initialised if used. Then
>> I predict that one of two things will happen
>> (a) people will end up writing boilerplace code at the start of the main
>> action which does
>> initialise1
>> initialise2
>> ... blah blah ...
>> (b) (more likely). There will be a single initialisation function for the
>> library, which initialises everything, even the stuff you don't
>> actually
>> want.
>
> To me this seems perfectly fine. Ian's proposal gets us TWIs, which I can see
> the need for. Implicit initialisation (i.e. stateful initialisation functions
> happening non-deterministicly, like java static{} blocks or C++'s similar
> feature) is a can of worms I currently see no value in opening.
It's true that ACIO only does some things: and that includes global
variables initialized with values. I think that's pretty useful; but
it's true that we don't get initializing with arbitrary IO activity.
Even when you do want to open the can of worms, things are better:
unsafePerformIO needs an accompanying NOINLINE pragma, whereas pushing
things through assertIOisACIO will guarantee execution no more than once.
I.
More information about the Haskell-Cafe
mailing list