[Haskell-cafe] Re: Top Level TWI's again was Re: [Haskell] Re: Parameterized Show

David Roundy droundy at abridgegame.org
Tue Nov 23 06:46:39 EST 2004

On Mon, Nov 22, 2004 at 08:32:33PM +0000, Graham Klyne wrote:
> [Switching to Haskell-cafe]
> At 11:26 22/11/04 +0000, you wrote:
> >I would ask an alternative question - is it possible to live without
> >unsafePerformIO? I have never needed to use it!

There are plenty of non-IO reasons to use unsafePerformIO, for which it is
essential.  If you want to write haskell code that uses a pointer
(allocated possibly via an FFI C routine), it has to be in the IO monad.
If you know that this pointer doesn't access memory that'll be changed at
random (or by other routines), you can (and *should*) safely use

Also, if you're interested in using weak pointers (for example, to do
memoization), you'll almost certainly need to use unsafePerformIO.  Again,
the result can, and should, be encapsulated, so the module that uses
unsafePerformIO exports only pure functions (unless of course, there are
any that actually perform IO).
David Roundy

More information about the Haskell-Cafe mailing list