Yetanotherpresentationon MONADS<br />MarcinGryszko<br />@mgryszko<br />
whyam I doingthis?<br />
accordingto Brian Marick…<br />http://www.vimeo.com/20717301<br />
Thereisanancient Mayan profecy<br />thatstatesthatsomedayevery single human onearthwillhave done a tutorial aboutmonads<br...
I’ll try to do my bit <br />so thathumanity can reach nirvana<br />
origins<br />
XVIII century<br />
Gottfried<br />1714 <br />Monadologie<br />
eternal <br />indecomposable<br />individual<br />hierarchical and aggregated<br />autonomic and independent<br />can chan...
XX century<br />
categorytheory<br />
abstractview of mathematical concepts (which are already quite abstract )<br />
categories have:<br />objects<br />morphisms or maps or arrows<br />see a relationship with<br />classes, objects and meth...
defines monad<br />howitisrelatedtofunctionalprogramming?<br />
functionalprogramming<br />
what are monads?<br />
containers<br />generalized interface for sequential computations<br />pattern for transmitting state using functions with...
what defines a monad?<br />
monadictypeM<br />java.util.List<br />unitoperation<br />value -> monad<br />constructor/factory method<br />[1, 2, 3] (In...
what does bind?<br />(typically)<br />
Take a function and apply it to all values inside the monad<br />Each invocation returns monad M<U><br />defintermediateMo...
monadic laws<br />(or when a monad is a monad)<br />
1. identity<br />m.bind { x -> unit(x) } ≡ m<br />transforming to unit doesn’t change a monad<br />
2. unit<br />unit(x).bind(f) ≡ f(x)<br />unit must preserve the value inside the monad<br />
3. associativity<br />m.bind(f).bind(g) ≡ <br />m.bind{ x -> f(x).bind(g) }<br />order of monad composition doesn’t matter...
monadic zeros<br />(optional, empty monad)<br />[]<br />
1. bindingwithzero<br />m.flatMap({ x -> mzero})≡ mzero<br />2. unit<br />mzero.bind(f) ≡ mzero<br />3. plus<br />mzero.pl...
examples<br />ListAsMonad<br />IO<br />State<br />Result<br />
sources<br />https://github.com/dsrkoc/monadologie<br />http://james-iry.blogspot.com/2007/09/monads-are-elephants-part-1....
Thank you!<br />
Upcoming SlideShare
Loading in...5
×

Groovy Monads

3,558

Published on

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

No Downloads
Views
Total Views
3,558
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
14
Comments
0
Likes
5
Embeds 0
No embeds

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 of "Groovy Monads"

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

      Clipping is a handy way to collect important slides you want to go back to later.

    ×