Pipes by Example Nick Partridge. nkpart on most things. Why Pipes - - PowerPoint PPT Presentation

pipes by example
SMART_READER_LITE
LIVE PREVIEW

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-1
SLIDE 1

Pipes by Example

Nick Partridge. nkpart on most things.

slide-2
SLIDE 2

Why Pipes

Because you’re writing a web server, of course.

slide-3
SLIDE 3

Not just for streaming!

produce :: m a consume :: a -> m ()

slide-4
SLIDE 4

Pipe Types

Lead, PVC, etc.

slide-5
SLIDE 5

Producers Consumers

+

Pipes

Proxy a a’ b b’ m c

slide-6
SLIDE 6

Pipe a b m r

a b m On exhaustion: r

Proxy () a () b m r

slide-7
SLIDE 7

Producer b m r

_ b m On exhaustion: r

Proxy X () () b m r

slide-8
SLIDE 8

Consumer a m r

a _ m On exhaustion: r

Proxy () a () X m r

slide-9
SLIDE 9

The Primitives

Because live coding always works.

slide-10
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
SLIDE 11

Elimination

Finally some Category Theory.

slide-12
SLIDE 12

Pipe a b m r

a b m On exhaustion: r

slide-13
SLIDE 13

Effect m r

m On exhaustion: r _ _

Proxy X () () X m r

slide-14
SLIDE 14

Substitution

Producers: for or ~> eliminates yield Consumer side: >~ eliminates await

slide-15
SLIDE 15

Elimination - Loop Bodies

for generator body

  • for x yield == x

for (yield x) f == f x

slide-16
SLIDE 16

Companion Libraries

Where the features are hiding.

slide-17
SLIDE 17

Companion Libraries

pipes-parse pipes-safe pipes-group

slide-18
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
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
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
SLIDE 21

return () :: Effect Talk ()

slide-22
SLIDE 22

References

Pipes haddocks - Pipes, Pipes.Prelude, Pipes.Tutorial Haskell for All - Gabriel Gonzales’ blog Haskell Pipes Google Group “pipes-“ seach on hackage