[Haskell-cafe] operations on lists with continuations

Evan Laforge qdunkan at gmail.com
Wed Mar 9 04:59:39 CET 2011

On Thu, Mar 3, 2011 at 12:33 AM, Mark Lentczner
<mark.lentczner at gmail.com> wrote:
> To make up for my total misunderstanding of what you were asking
> before, I hereby offer you the Plumbing module, available here:
>  https://bitbucket.org/mtnviewmark/haskell-playground/src/2d022b576c4e/Plumbing.hs
> With it, I think you can construct the kinds of pipelines you describe
> with the composition aspects you desire:

Indeed, it looks like a more thorough version of what I'm doing.  I'm
guessing the breaking into pairs thing would be ultimately more
composable, by which I mean lead to fewer special case functions.

>> :load Plumbing.hs
> [1 of 1] Compiling Plumbing         ( Plumbing.hs, interpreted )
> Ok, modules loaded: Plumbing.
>> let filterUntil cond start end = (passUntil (>=start) =|= pfilter cond) =+= passWhile (<end)
>> let filterUntilPlus1 cond start end = filterUntil cond start end =+= pass 1
>> filterUntil even 10 15 `pump` [1..]
> [2,4,6,8,10,11,12,13,14]
>> filterUntilPlus1 even 10 15 `pump` [1..]
> [2,4,6,8,10,11,12,13,14,15]

I would write the above as:

> let filterUntilPlus1 cond start end = Then.filter cond (>=start) $ Then.takeWhile (<end) $ take 1
> filterUntilPlus1 even 10 15 [1..]

I think mine is less flexible but it interacts with the basic list
functions more directly so it feels simpler to me.  In a way it
reminds me of STM, in that as long as you leave the last continuation
on, it's still "open" and can be composed.  But to get the actual
result, you have to stick a non-continuation function on the end, at
which point it no longer composes.  I suppose that's the model for
many many little DSLs though.

More information about the Haskell-Cafe mailing list