
jcast:
I was just meditating on array fusion using streams, and list fusion using streams, and it struck me: the definition of the list functions over arrays is the same as that of the list functions over lists. From the ByteString paper, we get:
Yes indeed, hence Data.Stream provides the common implemetations for both arrays, lists and a few other fusible sequence types.
map f = transformerBi (mapS f) foldr f z = consumerDn (foldrS f z) foldl f z = consumerUp (foldlS f z) replicate n = producerBi (replicateS n)
etc.
So why not say
class Sequence t alpha where consumerUp, consumerDn, consumerBi :: (Stream alpha -> beta) -> t alpha -> beta producerUp, producerDn, producerBi :: Stream alpha -> t alpha transformerUp, transformerDn, transformerBi :: Sequence t beta => (Stream alpha -> Stream beta) -> t alpha -> t beta
map :: Sequence t alpha => (alpha -> beta) -> t alpha -> t beta map f = transformerBi (mapS f)
You could do that, yep. -- Don