Ticket #60 (new enhancement)

Opened 21 months ago

Last modified 16 months ago

Add support for additional implementations of fusible functions

Reported by: rl Owned by:
Priority: major Milestone: 0.10
Version: Keywords:
Cc: haskell.org@…, v.dijk.bas@…

Description

The prime example is replicate: if it doesn't fuse, we really want it to use basicSet rather than unstream. There are many other functions like this. We don't really want to rely on rules for this because that would require an additional simplifier phase to work reliably. Rather, we'd want to implement replicate roughly like this:

unstreamOrElse :: Stream a -> v a -> v a
{-# INLINE_STREAM unstreamOrElse #-}
unstreamOrElse s x = x

{-# RULES

"stream/unstreamOrElse"
  stream (unstreamOrElse s x) = s

  #-}

replicate n x = unstreamOrElse (Stream.replicate n x)
                               (new (Mutable.replicate n x))

We'll probably also want streamOrElse:

streamOrElse :: (Stream a -> b) -> (v a -> b) -> v a -> b
{-# INLINE_STREAM streamOrElse #-}
streamOrElse f g = g

{-# RULES

"streamOrElse/unstream"
  streamOrElse f g (unstream s) = f s

"streamOrElse/unstreamOrElse"
  streamOrElse f g (unstreamOrElse s x) = f s

There are ways to keep the number of rules manageable (e.g., by making streamOrElse and unstreamOrElse the only streaming combinators.

Change History

Changed 19 months ago by liyang

  • cc haskell.org@… added

Changed 19 months ago by basvandijk

  • cc v.dijk.bas@… added

Changed 16 months ago by rl

  • milestone set to 0.10

Replication and concatenation is now fixed by changes to the fusion system. Other functions will follow soon. The approach I've taken is entirely different from the one suggested here and significantly more robust.

Note: See TracTickets for help on using tickets.