[Haskell-cafe] Re: Chameneos

Simon Marlow simonmar at microsoft.com
Fri Jan 6 06:14:43 EST 2006

Chris Kuklewicz wrote:
> Your "case" tweak was for an older version of Chameneos that used an
> older Ch channel implementation.
> But I was inspired by your improvement to use Int# instead of data
> Color, and I posted a version that seems faster than the winning one
> that was submitted. http://www.haskell.org/hawiki/ChameneosEntry
> It still has to box the Int# to put it into the MVar channels.  But the
> fastest complement is now (3# -# a -# b) and "if (other ==# faded)" is
> faster than the previous "case other of Faded -> ; _ ->".  At least on
> OS X / G4.
> Also, thanks for cleaning up the SumFile code.

I'm not keen on using explicit unboxed values in these benchmarks, since 
it looks so ugly.  In most cases you can convince GHC to do the unboxing 
for you, and I'm pretty sure it should be the case here too.  Just use 
ordinary Ints.

It's interesting you're getting some benefit from using integers instead 
of enumerations.  We've known for a while that enumerations in GHC 
aren't optimised as well as they could be.  So, at least for now, this 
is a useful trick: instead of

   data T = A | B | C


   newtype T = T Int

   a = T 1
   b = T 2
   c = T 3

and then GHC will be able to unbox T in a constructor field (ie. {-# 
UNPACK #-} !T will work), and it will also be able to unbox T in a 
strict argument position.

Of course you do lose the ability to do pattern matching.


More information about the Haskell-Cafe mailing list