[Haskell] Real life examples
john at repetae.net
Wed Nov 24 04:34:31 EST 2004
On Wed, Nov 24, 2004 at 01:35:53AM -0500, Judah Jacobson wrote:
> Very nice survey of practical applications! To futher clarify the
> discussion, though, I'd like to note two distinct uses of
> 1) encapsulating referentially transparent IO actions into pure functions
> 2) creating one-time-actions / top-level-mutable-variables / TWI's
> For example, in your example of Atom.hs, the top-level hashtable would
> be #2, while the pure external interface is #1. I believe your post
> addressed #2, please correct me if otherwise.
Ah yes, exactly. this is a very important point to bring up because the
two uses are actually quite different in a fundamental way.
#1 is safe-safe. in the fully safe meaning, as in all functional
transformations one expects to be valid remain valid on a truely
referentialy transparent pure function whether it is implemented
internally with unsafePerformIO or not. This is exactly the proper use
#2 unfortunatly, is the problem and I think the much more common use of
unsafePerformIO because there does not exist another workaround in
haskell for the top level initializer problem. It is an unsafe use of
unsafePerformIO, meaning there are generally valid language
transformations which change the meaning of programs using it and the
fact it has worked so well is just a coincidence of implementation.
The reason I only addressed #2 is because it is the only one that
actually has a technical problem that needs to be addressed :)
Part of my current interest in #2 is that I have been experimenting with
some full-program optimization algorithms which could perhaps give
substantial gains but would pretty much obliterate any uses of the
unsafePerformIO global variable hack, and no pragma can save them.
Before this, I never realized just how uncorrect the global variable use of
unsafePerformIO was :)
Thinking about this problem and realizing there is no in-language
solution without giving up certain key optimizations is what originally
motivated my previous concrete proposal based on the 'mdo' semantics.
John Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell