[Haskell-cafe] Building a monoid, continuation-passing style
Martijn van Steenbergen
martijn at van.steenbergen.nl
Mon Sep 14 11:25:28 EDT 2009
Inspired by Sean Leather's xformat package  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 .
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,
More information about the Haskell-Cafe