[Haskell-cafe] announce: Glome.hs raytracer
David Roundy
droundy at darcs.net
Wed Mar 26 20:17:49 EDT 2008
On Wed, Mar 26, 2008 at 05:07:10PM -0700, Don Stewart wrote:
> 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.
It depends what the point is. I've found traces to be very helpful at
times when debugging (for instance, to get values as well as counts).
Also, I imagine that manual tracing is likely to be far less invasive (if
you do it somewhat discretely) than profiling or using hpc.
--
David Roundy
Department of Physics
Oregon State University
More information about the Haskell-Cafe
mailing list