[Haskell-cafe] announce: Glome.hs raytracer

Don Stewart dons at galois.com
Wed Mar 26 20:07:10 EDT 2008


droundy:
> 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.

could we just use -fhpc or profiling here. HPC at least will tell you
how many times top level things are called, and print pretty graphs
about it.


More information about the Haskell-Cafe mailing list