[Haskell-cafe] Lazy cons, Stream-Fusion style?

Duncan Coutts duncan.coutts at googlemail.com
Sun Jan 2 20:54:47 CET 2011


On 2 January 2011 13:35, Stephen Tetley <stephen.tetley at gmail.com> wrote:
> Hello all
>
> Can a lazy cons be implemented for (infinite) Streams in the
> Stream-Fusion style?

In the standard stream fusion style, all stream operations are strict
in the stream itself (that is, the pair of stepper function and
initial state, not strict in the unfolded sequence or elements). Thus
it is not possible to write things like:

> bad_ones :: Stream Int
> bad_ones = s where s = 1 `S.cons` s

I'm not sure if making the stream operations lazy in the stream
argument (e.g. using an irrefutable ~pattern) would interfere with the
usual stream optimisations. It's an interesting question. The usual
optimisations rely on having access to the definitions of input
streams and will not apply to a circular definition such as the above.

This strictness issue isn't a semantic problem problem when applying
stream fusion to data structures like lists. A circular definition of
a list will simply not fuse (there is nowhere to apply the
stream/unstream rule).

Duncan



More information about the Haskell-Cafe mailing list