Uncurried-transformers - stack-safe monad transformers implemented using continuation-passing style

Hey everyone,

Inspired by @natefaubion’s work on making parsing fast and stack-safe, I recently found the time to write uncurried-transformers, an almost-drop-in replacement for the transformers library that’s more performant and stack-safe.

I say almost drop-in as:

  1. Because the internal representation is different, actions defined in terms of the newtype constructors would have to be converted to use MonadX operations instead. For example, ReaderT \r -> ... would become asks \r -> ...
  2. The signatures for the runner functions are flipped. So instead of runStateT action state, you’ll have to write runStateT state action. This is mostly an opinionated choice, since I don’t think there’s a reason to keep the order introduced by Haskell’s record accessors.

Here’s a very rudimentary benchmark, showcasing a self-recursive StateT action that counts up to a certain limit. It’s quite fast. Also, thanks a lot to Nate for walking me through the uncurried CPS approach, I’ve learned quite a lot implementing this library!

21 Likes