[Haskell-cafe] Building a monoid, continuation-passing style

Martijn van Steenbergen martijn at van.steenbergen.nl
Mon Sep 14 11:25:28 EDT 2009

Hello cafe,

Inspired by Sean Leather's xformat package [1] I built a datatype with 
which you can build a monoid with holes, yielding a function type to 
fill in these holes, continuation-passing style. Here are some 
primitives and their types:

> now   :: m -> ContSt m r r
> later :: (a -> m) -> ContSt m r (a -> r)
> run   :: ContSt m m r -> r
> instance Monoid m => Category (ContSt m)

Here's an example of how to use it:

> run (now "hello" . now "world")

> run (later id . now "world") "hello"

> run (later id . later show) "hello" 567

The source code is available at [2].

I have a couple of questions:
* ContSt is a Category. Is it also an Arrow? Why (not)?
* Did I miss any other obvious classes this type is an instance of?
* What is its relation with the Cont and Reader monads?
* Are there any other useful applications other than printf-like 
* ContSt is a horrible name. What is a better one?

For those who have a bit more time: I appreciate any comments and 
suggestions on the code. :-)

Many thanks in advance,


[1] http://hackage.haskell.org/package/xformat
[2] http://code.google.com/p/monoid-cont/source/browse/trunk/ContSt.hs

More information about the Haskell-Cafe mailing list