SLIDE 1
Pipes by Example Nick Partridge. nkpart on most things. Why Pipes - - PowerPoint PPT Presentation
Pipes by Example Nick Partridge. nkpart on most things. Why Pipes - - PowerPoint PPT Presentation
Pipes by Example Nick Partridge. nkpart on most things. Why Pipes Because youre 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
SLIDE 2
SLIDE 3
Not just for streaming!
produce :: m a consume :: a -> m ()
SLIDE 4
Pipe Types
Lead, PVC, etc.
SLIDE 5
Producers Consumers
+
Pipes
Proxy a a’ b b’ m c
SLIDE 6
Pipe a b m r
a b m On exhaustion: r
Proxy () a () b m r
SLIDE 7
Producer b m r
_ b m On exhaustion: r
Proxy X () () b m r
SLIDE 8
Consumer a m r
a _ m On exhaustion: r
Proxy () a () X m r
SLIDE 9
The Primitives
Because live coding always works.
SLIDE 10
Use the Monad
Running producers sequentially is just >> When pipes/consumers/producers/finish, they return a value Control.Monad and friends are very useful.
SLIDE 11
Elimination
Finally some Category Theory.
SLIDE 12
Pipe a b m r
a b m On exhaustion: r
SLIDE 13
Effect m r
m On exhaustion: r _ _
Proxy X () () X m r
SLIDE 14
Substitution
Producers: for or ~> eliminates yield Consumer side: >~ eliminates await
SLIDE 15
Elimination - Loop Bodies
for generator body
- for x yield == x
for (yield x) f == f x
SLIDE 16
Companion Libraries
Where the features are hiding.
SLIDE 17
Companion Libraries
pipes-parse pipes-safe pipes-group
SLIDE 18
- 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.
SLIDE 19
- 2. Pipes Safe
ReaderT (IORef (Finalizers m)) m r Resource management, exception safety, through a monad transformer on m that allows registering Finalizers.
SLIDE 20
- 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
SLIDE 21
return () :: Effect Talk ()
SLIDE 22