Pipes by Example Nick Partridge. nkpart on most things.
Why Pipes Because you’re writing a web server, of course.
Not just for streaming! produce :: m a consume :: a -> m ()
Pipe Types Lead, PVC, etc.
Producers + Consumers Pipes Proxy a a’ b b’ m c
m a b Pipe a b m r On exhaustion: r Proxy () a () b m r
m _ b Producer b m r On exhaustion: r Proxy X () () b m r
m a _ Consumer a m r On exhaustion: r Proxy () a () X m r
The Primitives Because live coding always works.
Use the Monad Running producers sequentially is just >> When pipes/consumers/producers/finish, they return a value Control.Monad and friends are very useful.
Elimination Finally some Category Theory.
m a b Pipe a b m r On exhaustion: r
m _ _ Effect m r On exhaustion: r Proxy X () () X m r
Substitution Producers: for or ~> eliminates yield Consumer side: >~ eliminates await
Elimination - Loop Bodies for generator body � for x yield == x for (yield x) f == f x
Companion Libraries Where the features are hiding.
Companion Libraries pipes-parse pipes-safe pipes-group
1. Pipes Parse type Parser a m r = forall x. StateT (Producer a m x) m r Provides ‘push-back’. You can modify the underlying producer to return a value again.
2. Pipes Safe ReaderT (IORef (Finalizers m)) m r Resource management, exception safety, through a monad transformer on m that allows registering Finalizers.
3. Pipes Group FreeT (Producer a m) m x Working on sub-streams in constant memory. a ‘linked-list’ of sub-stream producers, each one returning the next sub-stream on exhaustion
return () :: Effect Talk ()
References Pipes haddocks - Pipes, Pipes.Prelude, Pipes.Tutorial Haskell for All - Gabriel Gonzales’ blog Haskell Pipes Google Group “pipes-“ seach on hackage
Recommend
More recommend