haskellconduit

"List like" conduit newtype


We've got a bunch of code currently using lists which probably should be using conduit.

But this occurred to me:

newtype ListyConduit r m i o = ListyConduit (ConduitT i o m r)

instance Functor (ListyConduit r m i) where
  ...

instance Foldable (ListyConduit r m i) where
  ...

instance Traversable (ListyConduit r m i) where
  ...

instance Profunctor (ListConduit r m) where
  ...

This approach would simply the conversion as in most cases I'll just have to generalise [a] to f a and then I can just put conduits in with the existing logic.

And it seems to me that each of these instances should be writable (at least I think) in a way that preserves the constant space usage of conduits.

Is this a reasonable assumption, and if so, has someone already done what I'm proposing above? And if it hasn't been done, is it because my suggestion is quite silly in some way or has no-one just got around to it?


Solution

  • There are quite a few problems here:

    Basically: list code that can generalize to Conduit is pure and should already be streaming, if that is possible; there's no point in using Conduit here. When list code doesn't stream, the main culprit is effects (i.e. a traverse), and making it stream by using Conduit will not be "free". Such code has already traded away the capacity to stream effects for simplicity.