[Haskell-cafe] Re: [Haskell] Top Level <-

Adrian Hey ahey at iee.org
Wed Aug 27 06:53:19 EDT 2008

John Meacham wrote:
> As with all design decisions, it is sometimes the right thing and
> sometimes the wrong one. And sometimes the most expedient. (which,
> occasionally, is a perfectly valid driving force behind a certain bit of
> coding). However, I am fully convinced it is necessary. You don't even
> have to look further than Haskell 98 to find a use in the Random module,
> and Data.Unique _depends_ on the state being global for correctness.

..and of course there's stdin, stdout. That takes some explaining. Even
with the proposed ACIO and top level <- bindings I still couldn't
implement a lib that exported a top level nonStdout handle. It'd have to
be a getNonStdout IO action.

Regarding the necessity of "global variables", despite what I've been
saying it is of course possible to implement entire systems
(programs/processes or whatever main corresponds to) without them if
you don't mind explicitly creating all those micro states immediately
on entry to main and passing the references around.

But this is a highly unmodular, inconvenient, unsafe (because you must
expose and allow potentially uncontrained use of newWhateverMicroState
constuctors) and a general maintainance nightmare. Definitely not the
way to go IMO.

So it would be more accurate to say that IMO it's impossible to
implement many sane and inherently safe IO lib APIs without using
"global variables". But people who prefer insane and inherently unsafe
APIs could live without them quite happily I guess :-)

Adrian Hey

More information about the Haskell-Cafe mailing list