[Haskell-cafe] ANNOUNCE: pipes-core 0.1.0

Paolo Capriotti p.capriotti at gmail.com
Wed Apr 18 00:11:55 CEST 2012


On Tue, Apr 17, 2012 at 4:10 PM, Chris Smith <cdsmith at gmail.com> wrote:
> One thing that Gabriel and
> Michael have been talking about, though, that seems to be missing
> here, is a way for a pipe to indicate that it's finished with its
> upstream portion, so that upstream finalizers can be immediately run
> without waiting for the downstream parts of the pipe to complete.

Yes, that is indeed a limitation of pipes-core, but it's still
possible to achieve early finalization when needed, by explicitly
returning a "continuation" pipe. The following operator

(>!>) :: Monad m
      => Pipe a b m r
      -> Pipe b c m (Pipe a c m r)
      -> Pipe a c m r
p1 >!> p2 = do
  r0 <- (Left <$> p1) >+> (Right <$> p2)
  case r0 of
    Left r -> return r
    Right p' -> p'

could be used to compose such a pipe. Alternatively, one can use
'Control.Pipe.Zip.controllable' together with 'loopP' (there's a
similar example in pipes-extra/Examples/finalizers/complex.hs).

Unfortunately, both approaches are not compositional. They require you
to structure the whole pipeline around them.

I suspect it might be possible to incorporate these ideas into the
Pipe type without losing associativity, but I don't have any
motivating examples where this feature would actually be useful. Do
you have anything in mind, Chris?

BR,
Paolo



More information about the Haskell-Cafe mailing list