Ticket #60 (new enhancement)
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
Note: See
TracTickets for help on using
tickets.
