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

Max Bolingbroke batterseapower at hotmail.com
Mon Jan 3 21:17:29 CET 2011


Hi Stephen,

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

I made a mailing list post about almost exactly this issue a while ago
(http://www.mail-archive.com/haskell-cafe@haskell.org/msg82981.html).
There was no really nice solution offered: I think the best you can do
is define your stream operations with a lazy pattern match using my
"eta" trick from that post:

  eta stream = Stream (case stream of Stream s _ -> unsafeCoerce s ::
()) (case stream of Stream _ step -> unsafeCoerce step)

Then instead of writing:

 f (Stream x y) = ...

Write:

  f (eta -> Stream x y) = ...

(This is necessary because lazy pattern matches on existential data
constructors using ~ cannot even be expressed in System FC, so it is
unclear how GHC could implement them).

Cheers,
Max



More information about the Haskell-Cafe mailing list