[Haskell-cafe] Sequence Classes

Jonathan Cast jcast at ou.edu
Tue Jul 10 11:59:41 EDT 2007


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:

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)

etc.?

Jonathan Cast
http://sourceforge.net/projects/fid-core
http://sourceforge.net/projects/fid-emacs


More information about the Haskell-Cafe mailing list