[Haskell-cafe] Much faster complex monad stack based on CPS state

Nicu Ionita nicu.ionita at acons.at
Tue Sep 27 01:07:00 CEST 2011


Hello list,

Starting from this emails 
(http://web.archiveorange.com/archive/v/nDNOvSM4JT3GJRSjOm9P) I could 
refactor my code (a UCI chess engine, with complex functions, in which 
the search has a complex monad stack) to run twice as fast as with even 
some hand unroled state transformer! So from 23-24 kilo nodes per second 
it does now 45 to 50 kNps! And it looks like there is still some 
improvement room (I have to play a little bit with strictness 
annotations and so on).

(Previously I tried specializations, then I removed a lot of 
polimorphism, but nothing helped, it was like hitting a wall.)

Even more amazingly is that I could program it although I cannot really 
understand the Cont & ContT, but just taking the code example from Ryan 
Ingram (newtype ContState r s a = ...) and looking a bit at the code 
from ContT (from the transformers library), and after fixing some 
compilation errors, it worked and was so fast.

I wonder why the transformers library does not use this kind of state 
monad definition. Or does it, and what I got is just because of the 
unrolling? Are there monad (transformers) libraries which are faster? I 
saw the library kan-extensions but I did not understand (yet) how to use it.

Nicu



More information about the Haskell-Cafe mailing list