[Haskell-cafe] announce: Glome.hs raytracer

David Roundy droundy at darcs.net
Wed Mar 26 20:02:39 EDT 2008

On Thu, Mar 27, 2008 at 01:09:47AM +0300, Bulat Ziganshin wrote:
> > -Collecting rendering stats is not easy without global variables.  It
> > occurs to me that it would be neat if there were some sort of write-only
> > global variables that can be incremented by pure code but can only be 
> > read from within monadic code; that would be sufficient to ensure that
> > the pure code wasn't affected by the values.
> the code is called *pure* exactly because it has no side-effects and
> compiler may select either to call some function two times or reuse
> already computed result. actually, you can make sideeffects with
> unsafePerformIO, but there is no guarantees of how many times such
> code will be executed. try this:
> plus a b = unsafePerformIO (modifyIORef counter (+1)) `seq` a+b

This is exactly what he wants to do.  The point of putting traces into the
code is precisely to figure out how many times it is called.  The only
trouble is that unsafePerformIO (I believe) can inhibit optimizations,
since there are certain transformations that ghc won't do to
unsafePerformIO code.
David Roundy
Department of Physics
Oregon State University

More information about the Haskell-Cafe mailing list