• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Docase notation for Haskell
 

Docase notation for Haskell

on

  • 1,054 views

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).

Statistics

Views

Total Views
1,054
Views on SlideShare
1,054
Embed Views
0

Actions

Likes
1
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Docase notation for Haskell Docase notation for Haskell Presentation Transcript

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