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

Keean Schupke k.schupke at imperial.ac.uk
Tue Nov 23 08:51:24 EST 2004


David Roundy wrote:

>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
>unsafePerformIO.
>  
>
Does it? cant you just declare:

import foreign ccall "somefn" somefn :: Ptr Double -> Ptr Double

>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).
>  
>
Don't know about this one, got a short example?

    Keean.



More information about the Haskell-Cafe mailing list