[Shootout-list] Regexmatch woes with Haskell

Einar Karttunen ekarttun@cs.helsinki.fi
Tue, 08 Mar 2005 12:19:38 +0200


Hello

Implementing regexmatch correctly in Haskell seems quite problematic. 
The current implementation works with ghc 6.2.2 but ghc 6.4 
(some weeks from now) will kill even that. The main problem is that
the benchmark is of the type: "while(n >= 0) { x; } print x" where
x is a pure operation. The GHC optimizer looks at that and generates
code for "print x" - as the thing inside the loop is not used for
anything and has no side-effects. 

One can add various kludges (long lines of extremely ugly code)
to foul the optimizer - but with regexmatch the amount/complexity of
kludge is becoming harder than the benchmark in itself. 

Also it is usually to hard to get the kludge do the right amount of 
work - with different kludges one gets very different performance
depending whether they e.g. eat stack too and whether they really
have killed all of the optimization.

- Einar Karttunen