[Haskell-cafe] ZipList monad, anyone?

Patai Gergely patai_gergely at fastmail.fm
Wed Apr 1 06:44:35 EDT 2009

Does ZipList have any useful monad instance? The thought came up while
thinking about higher order dataflows and an ArrowApply interface for
Yampa. As a ZipList can be thought of as a function with a discrete
domain, I figured its monadic form could be analogous to the reader
monad, hence:

instance Monad ZipList where
    return = ZipList . repeat
    ZipList xs >>= f = ZipList $ zipWith ((!!) . getZipList . f) xs

Correct me if I'm wrong, but it seems to me that f always returning an
infinite list is a sufficient condition for the monad laws to hold.
However, this is painfully inefficient. I assume that bringing FRP-like
switching and some clever data structure (which optimises stateless
streams for starters) into the picture can potentially lead to
constant-time access at least in the case of sequential sampling. Is
there any recent work going in this direction?


http://www.fastmail.fm - One of many happy users:

More information about the Haskell-Cafe mailing list