pipes by example
play

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


  1. Pipes by Example Nick Partridge. nkpart on most things.

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

  3. Not just for streaming! produce :: m a consume :: a -> m ()

  4. Pipe Types Lead, PVC, etc.

  5. Producers + Consumers Pipes Proxy a a’ b b’ m c

  6. m a b Pipe a b m r On exhaustion: r Proxy () a () b m r

  7. m _ b Producer b m r On exhaustion: r Proxy X () () b m r

  8. m a _ Consumer a m r On exhaustion: r Proxy () a () X m r

  9. The Primitives Because live coding always works.

  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.

  11. Elimination Finally some Category Theory.

  12. m a b Pipe a b m r On exhaustion: r

  13. m _ _ Effect m r On exhaustion: r Proxy X () () X m r

  14. Substitution Producers: for or ~> eliminates yield Consumer side: >~ eliminates await

  15. Elimination - Loop Bodies for generator body � for x yield == x for (yield x) f == f x

  16. Companion Libraries Where the features are hiding.

  17. Companion Libraries pipes-parse pipes-safe pipes-group

  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.

  19. 2. Pipes Safe ReaderT (IORef (Finalizers m)) m r Resource management, exception safety, through a monad transformer on m that allows registering Finalizers.

  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

  21. return () :: Effect Talk ()

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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend