Your SlideShare is downloading. ×
0
Docase notation for Haskell
Docase notation for Haskell
Docase notation for Haskell
Docase notation for Haskell
Docase notation for Haskell
Docase notation for Haskell
Docase notation for Haskell
Docase notation for Haskell
Docase notation for Haskell
Docase notation for Haskell
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Docase notation for Haskell

818

Published on

Slides from a brief presentation about the 'docase' notation that I did at Haskell Hackathon in Cambridge. The notation makes it easier to work with monads that have some additional operations (such …

Slides from a brief presentation about the 'docase' notation that I did at Haskell Hackathon in Cambridge. The notation makes it easier to work with monads that have some additional operations (such as Par monad or Parsers).

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
818
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Monadic pattern matching with ‘docase’<br />Tomáš Petříček(tomas.petricek@cl.cam.ac.uk)University of Cambridge, UK<br />Advisors: Alan Mycroft, Don Syme<br />
  • 2. Introduction<br />Warm Fuzzy Things (aka Monads)<br />Sequencing of effectful computations<br />Used for parallel & concurrent programming <br />Extend monad interface with additional operations<br />spawn :: Par a -> Par (IVar a) get :: Ivar a -> Par a<br />What are common additional operations?<br />Is there nice notation for using them?<br />
  • 3. Multiplying future values<br />Future values<br />Compute resultin background<br />Pattern matching<br />“a” waits for a value<br />Suspended computation<br />Run both<br />multiply f1 f2 =<br />docase(f1, f2) of<br />(a, b) -> return (a * b)<br />
  • 4. Multiplying future values<br />Future values<br />Compute resultin background<br />Pattern matching<br />“a”waits for a value<br />“?” does not needa value to match<br />“0” waits for aspecific value<br />Run both<br />multiply f1 f2 =<br />docase(f1, f2) of<br /> (0, ?) -> return 0<br /> (?, 0) -> return 0<br />(a, b) -> return (a * b)<br />Choice<br />
  • 5. Multiplying future values<br />Future values<br />Compute resultin background<br />Pattern matching<br />“a” waits for a value<br />“?” does not needa value to match<br />“0” waits for aspecific value<br />Run both<br />multiply f1 f2 =<br />docase(f1, f2) of<br /> (0, ?) -> return 0<br /> (?, 0) -> return 0<br />(a, b) -> return (a * b)<br />Choice<br />Fail<br />
  • 6. Introduction<br />Monad with three additional operations<br />Parallel composition<br /> m a -> m b -> m (a, b)<br />Monadic choice<br /> m a -> m a -> m a<br />Aliasing of computations<br />m a -> m (m a)<br />Some of them supported by many monads<br />Parallel programming (Par monad)<br />Parsers for textual input (Parser monad)<br />Reactive & concurrent (Orcmonad?, Chpmonad?)<br />
  • 7. Parsing using Joinads<br />Validating Cambridge phone numbers<br />Contain only digits<br />Consists of 10 characters<br />Start with a prefix “1223”<br />Represents intersection of languages<br />Returns results of all three parsers<br />valid = docase( many (satisfies isDigit),<br /> multiple 10 character,<br />startsWith(string "1223") )<br />of (str, _, _) -> return str<br />
  • 8. Printing buffer using joins<br />Join calculus<br />Channels store values<br />Joins specifyreactions<br />Pattern matching<br />Use clauses to encode joins<br />let buffer() =<br />docase (get, putInt, putString) of<br />(r, n, ?) -> <br /> reply r (intToString n)<br />(r, ?, s) -> <br /> reply r s<br />First clause<br />Second clause<br />Second clause<br />putInt<br />putString<br />get<br />
  • 9. Joinads as an algebraic structure<br />Set 𝓙 representing “joinadic” computations<br />Constant 0 and associative operators ⊗, ⊕:<br />a ⊗ 0 = 0<br />a ⊕ 0 = a<br />a ⊗ b = b ⊗a<br />a ⊗ (b ⊕ c) = (a ⊗ b) ⊕ (a ⊗ c)<br />(𝓙, ⊕, ⊗, 0) is a commutative near-semiring<br />
  • 10. Summary<br />Related to new monad comprehensions<br />Allows expressing parallel composition <br />Reuse the MonadZiptype class <br />Free for commutative monads<br />Future plans<br />Implementing GHC language extension<br />Looking for more Monad examples<br />For more information<br />http://tomasp.net/blog/docase-haskell.aspx<br />http://tomasp.net/blog/comprefun.aspx<br />

×