[Haskell-cafe] Lazy Lists and IO - Redux

Dan Piponi dpiponi at gmail.com
Fri Jul 13 15:39:05 EDT 2007


On 7/13/07, Ronald Guida <ronguida at mindspring.com> wrote:
> [Ronald Guida, 07/11/07]
>  > Now I want to connect the console to "f", such that the list of inputs
>  > to "f" comes from the console, one item at a time.
> How do I do this?
>
> [Stefan O'Rear]
>  > Not very nicely.
>
> Apparently, the solution gets ugly.

If we have to throw in the towel for a request that is so elementary,
surely it means that pure functional programming is broken. Let's not
throw in the towel just yet...

We just need a bunch of library functions. We hide the ugliness in the library.

Rather than post an overlong mail here's some code I threw together
last night building on "ListT done right" on the Wiki:
http://hpaste.org/1657

The library itself looks ugly but scroll to the end where you see I
use 'lifted' versions of foldl, foldlM, filter and takeWhile. It works
with ghc, it's easy to use and the input and output are fully
interleaved. The IO is almost completely decoupled from the logic.

It'd be nice to put together a more complete library that does this
kind of stuff.

An interesting project might be to try defining a "GeneralisedList"
type class of which [] and ListT are both instances so we don't need
to distinguish between filter and filterT, say. Then we could make
interleaving IO and lists fairly transparent.

(And sorry if I'm duplicating what someone else said. The thread is
long and I haven't read every word of all of it.)
--
Dan


More information about the Haskell-Cafe mailing list