Your SlideShare is downloading. ×
0
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
Groovy Monads
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

Groovy Monads

3,484

Published on

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

No Downloads
Views
Total Views
3,484
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
14
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<br />MarcinGryszko<br />@mgryszko<br />
    • 2. whyam I doingthis?<br />
    • 3. accordingto Brian Marick…<br />http://www.vimeo.com/20717301<br />
    • 4. Thereisanancient Mayan profecy<br />thatstatesthatsomedayevery single human onearthwillhave done a tutorial aboutmonads<br />and onthatpointthepurpose of theuniversewillhavebeenachieved<br />and allhumanswillascenttoparadise<br />
    • 5. I’ll try to do my bit <br />so thathumanity can reach nirvana<br />
    • 6. origins<br />
    • 7. XVIII century<br />
    • 8. Gottfried<br />1714 <br />Monadologie<br />
    • 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. XX century<br />
    • 11. categorytheory<br />
    • 12. abstractview of mathematical concepts (which are already quite abstract )<br />
    • 13. categories have:<br />objects<br />morphisms or maps or arrows<br />see a relationship with<br />classes, objects and methods?<br />
    • 14. defines monad<br />howitisrelatedtofunctionalprogramming?<br />
    • 15. functionalprogramming<br />
    • 16. what are monads?<br />
    • 17. containers<br />generalized interface for sequential computations<br />pattern for transmitting state using functions without mutation<br />
    • 18. what defines a monad?<br />
    • 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. what does bind?<br />(typically)<br />
    • 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. monadic laws<br />(or when a monad is a monad)<br />
    • 23. 1. identity<br />m.bind { x -> unit(x) } ≡ m<br />transforming to unit doesn’t change a monad<br />
    • 24. 2. unit<br />unit(x).bind(f) ≡ f(x)<br />unit must preserve the value inside the monad<br />
    • 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. monadic zeros<br />(optional, empty monad)<br />[]<br />
    • 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. examples<br />ListAsMonad<br />IO<br />State<br />Result<br />
    • 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. Thank you!<br />

    ×