Your SlideShare is downloading. ×

Groovy Monads

3,422

Published on

Published in: Technology, Design
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,422
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
5
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
  • Individual -each has its own identityAutonomic and independent - interactions are only apparentCan change itself according to some intrinsic laws -but the change comes from insideHierarchical and aggregated – complex monads can be composed from simple monads
  • Transcript

    • 1. Yetanotherpresentationon MONADS
      MarcinGryszko
      @mgryszko
    • 2. whyam I doingthis?
    • 3. accordingto Brian Marick…
      http://www.vimeo.com/20717301
    • 4. Thereisanancient Mayan profecy
      thatstatesthatsomedayevery single human onearthwillhave done a tutorial aboutmonads
      and onthatpointthepurpose of theuniversewillhavebeenachieved
      and allhumanswillascenttoparadise
    • 5. I’ll try to do my bit
      so thathumanity can reach nirvana
    • 6. origins
    • 7. XVIII century
    • 8. Gottfried
      1714
      Monadologie
    • 9. eternal
      indecomposable
      individual
      hierarchical and aggregated
      autonomic and independent
      can change itself according to some intrinsic laws
      infinite
      space, time matter, and motion are phenomenal
      atom
      human being
      soul
      god – first monad
      ultimate elements of the universe
    • 10. XX century
    • 11. categorytheory
    • 12. abstractview of mathematical concepts (which are already quite abstract )
    • 13. categories have:
      objects
      morphisms or maps or arrows
      see a relationship with
      classes, objects and methods?
    • 14. defines monad
      howitisrelatedtofunctionalprogramming?
    • 15. functionalprogramming
    • 16. what are monads?
    • 17. containers
      generalized interface for sequential computations
      pattern for transmitting state using functions without mutation
    • 18. what defines a monad?
    • 19. monadictypeM
      java.util.List
      unitoperation
      value -> monad
      constructor/factory method
      [1, 2, 3] (Integer -> List<Integer>)
      bindoperation
      monad -> next monad, exposing its internal value for a transformation function
      any method in Groovy taking a closure as param
      [1, 2, 3].bind({ x -> [x, x + 1] })
      == [1, 2, 2, 3, 3, 4]
    • 20. what does bind?
      (typically)
    • 21. Take a function and apply it to all values inside the monad
      Each invocation returns monad M<U>
      defintermediateMonads =
      collect { x -> f(x) }
      Extract U values from all intermediate M<U> monads and assemble the final M<U> monad
      intermediateMonads.flatten()
    • 22. monadic laws
      (or when a monad is a monad)
    • 23. 1. identity
      m.bind { x -> unit(x) } ≡ m
      transforming to unit doesn’t change a monad
    • 24. 2. unit
      unit(x).bind(f) ≡ f(x)
      unit must preserve the value inside the monad
    • 25. 3. associativity
      m.bind(f).bind(g) ≡
      m.bind{ x -> f(x).bind(g) }
      order of monad composition doesn’t matter
    • 26. monadic zeros
      (optional, empty monad)
      []
    • 27. 1. bindingwithzero
      m.flatMap({ x -> mzero})≡ mzero
      2. unit
      mzero.bind(f) ≡ mzero
      3. plus
      mzero.plus(m) ≡ m
      m.plus(mzero) ≡ m
    • 28. examples
      ListAsMonad
      IO
      State
      Result
    • 29. sources
      https://github.com/dsrkoc/monadologie
      http://james-iry.blogspot.com/2007/09/monads-are-elephants-part-1.html
      http://james-iry.blogspot.com/2007/10/monads-are-elephants-part-2.html
      http://james-iry.blogspot.com/2007/10/monads-are-elephants-part-3.html
      http://james-iry.blogspot.com/2007/11/monads-are-elephants-part-4.html
    • 30. Thank you!

    ×