[Haskell-cafe] Is there a GHC flag that will allow mutable top level state while you are debugging and then ...

Francesco Mazzoli f at mazzo.li
Thu Jul 5 16:56:09 CEST 2012

At Wed, 4 Jul 2012 09:06:32 -0700,
KC  wrote:
> you can turn the flag off when you are ready to do the computational
> heavy lifting so that you don't have to modify your code base?
> That is, GHC can then apply its algebraic transformation
> optimizations to the "code algebra" of the pure functions.

What do you mean "allow mutable top level state"? As in

> import Foreign.Ptr
> import Foreign.StablePtr
> import Foreign.Storable
> import System.IO.Unsafe
> destructiveUpdate :: Storable a => a -> a -> ()
> destructiveUpdate x y =
>     unsafePerformIO $ do ptr <- newStablePtr x
>                          poke (castPtr (castStablePtrToPtr ptr)) y
>                          freeStablePtr ptr

? The only problem that the above function does not work - you can't
poke or peek off StablePtrs.

If that's what you mean, no. And I doubt it'll ever exist, since it
breaks the most important invariant in Haskell - that is, that values
don't change. An Haskell compiler will rely on this assumption quite
heavily, so changes to that are likely to disrupt things seriously.

Also, I don't see how destructive updates help debugging.

Francesco * Often in error, never in doubt

More information about the Haskell-Cafe mailing list