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

2011-09-28 Thread Nicu Ionita
Am 28.09.2011 02:35, schrieb Ryan Ingram: My guess is that Cont plays really nicely with GHC's inliner, so things that end up looking like return x >>= \y -> ... get optimized really well return x >>= f -- inline >>= = ContState $ \s0 k -> runCS (return x) s0 $ \a s1 -> runCS (f

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

2011-09-28 Thread Nicu Ionita
Am 28.09.2011 14:05, schrieb Yves Parès: Interesting, so what have you used to get that speedup? A monad stack of ContT and State (*)? Just the Cont monad? This is a module with a state monad transformer that I used before (the name STPlus is misleading - and sorry for the long email): {-# LA

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

2011-09-28 Thread Thomas Schilling
Well, you can get something close with the help of IORefs, but I forgot the details. I believe this is the paper that explains it: "Value recursion in the continuation monad" by Magnus Carlsson http://www.carlssonia.org/ogi/mdo-callcc.pdf On 28 September 2011 15:15, Bas van Dijk wrote: > On 28

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

2011-09-28 Thread Bas van Dijk
On 28 September 2011 14:25, Ertugrul Soeylemez wrote: > Bas van Dijk wrote: > >> Because of this reason I don't provide a MonadTransControl instance >> for ContT in monad-control[2]. > > Is that even possible? I once tried and failed so I believe it's not possible. Bas

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

2011-09-28 Thread Ertugrul Soeylemez
Bas van Dijk wrote: > Because of this reason I don't provide a MonadTransControl instance > for ContT in monad-control[2]. Is that even possible? I tried hard to come up with just a MonadFix instance for CPS-based monads, and I failed. I would think that MonadTransControl is just as hard, if n

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

2011-09-28 Thread Yves Parès
Interesting, so what have you used to get that speedup? A monad stack of ContT and State (*)? Just the Cont monad? (*) If so, were you using the strict version of State? Would it be possible to see the differences between the 2 versions of you code? 2011/9/27 Nicu Ionita > Hello list, > > Star

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

2011-09-28 Thread Bas van Dijk
On 27 September 2011 01:07, Nicu Ionita wrote: > I wonder why the transformers library does not use this kind of state monad > definition. One disadvantage of ContT and I guess any CPS based monad transformer is that they interact badly with exception handling functions like catch. See [1] for a

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

2011-09-27 Thread Ryan Ingram
My guess is that Cont plays really nicely with GHC's inliner, so things that end up looking like return x >>= \y -> ... get optimized really well return x >>= f -- inline >>= = ContState $ \s0 k -> runCS (return x) s0 $ \a s1 -> runCS (f a) s1 k -- inline return = ContState

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

2011-09-26 Thread Nicu Ionita
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 fr