SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
MONAD ON GROOVY
      ==
 MANADOLOGIE
   masaki@metabolics.co.jp
         2011.06.17


                             1
monad?


                           Haskell

         monoid

continuation

......


                                     2
monad!

          (                          )



Haskell




              Maybe Monad   Groovy       (2009/8/30, Gr   )


                                                              3
example 1
                         2
    S = {2x|x ∈ N, x > 3}


            (comprehension)

x      3                      ,2 *x




                                      4
groovy way

def s(n) {
     ((0..n)
        .findAll { it**2 > 3 })
        .collect { it*2 }
}


    Groovy                  ,


                                 5
example 2
import static hr.helix.monadologie.MonadComprehension.foreach
def s(n) {
   foreach {
       x = takeFrom { 0..n }
       guard { x**2 > 3 }
       yield { 2*x }
   }
}



                                                                6
example 3
def pythags(n) {
   foreach {
       z = takeFrom { 1..n }
       x = takeFrom { 1..z }
       y = takeFrom { x..z }
       guard { x**2 + y**2 == z**2 }
       yield { [x, y, z] }
   }
}
assert pythags(12) == [[3, 4, 5], [6, 8, 10]]




                                                7
monadologie

 https://github.com/dsrkoc/monadologie

 by Dinko Srkoc




                                         8
what’s the point


monadologie            ?

=>        Collection       ,




                               9
interface Monad<M> {

    M unit(Object a)

    M bind(Closure f)

}




                        10
List                                (!)

  (List<X>          X                        )

List<X>          (X a) = { [a] } //

List<Y>          (List<X> m, f) =
  { m.inject([]) { r, e -> r + f(e) } } //

  // where f s.t. List<Y> f(X x)

  // f   apply                          []


                                                   11
unit, bind

bind(m, unit) == m

bind(unit(m), f) == f(m) //

bind(bind(m, f), g) ==
  bind(m, { bind(f(it), g) }) //




                                   12
Groovy                         ?

=> List (Collection)



             ,
                       (   )

       ...



                                   13
Option -       (e.g. null)

           Maybe Groovy safe reference “?.”

Either -

Reader -                 Closure

Writer -

State -

STM -

memoize,   ,

AST




                                              14
,   ?




                 (   )




        ...:-)



                         15
LT




     16

Weitere ähnliche Inhalte

Was ist angesagt?

「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)
Hiroki Mizuno
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
anishgoel
 
Pratikum 2 urai wira s
Pratikum 2 urai wira sPratikum 2 urai wira s
Pratikum 2 urai wira s
Wirha Sykerz
 
Pratikum 1 hardiansyah
Pratikum 1 hardiansyahPratikum 1 hardiansyah
Pratikum 1 hardiansyah
Wirha Sykerz
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
Moriyoshi Koizumi
 

Was ist angesagt? (20)

Img082
Img082Img082
Img082
 
プログラミングHaskell 13章 問題7
プログラミングHaskell 13章 問題7プログラミングHaskell 13章 問題7
プログラミングHaskell 13章 問題7
 
MessagePack - An efficient binary serialization format
MessagePack - An efficient binary serialization formatMessagePack - An efficient binary serialization format
MessagePack - An efficient binary serialization format
 
Mathcad - modified secant method 2
Mathcad - modified secant method 2Mathcad - modified secant method 2
Mathcad - modified secant method 2
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
 
2008 june 10
2008 june 102008 june 10
2008 june 10
 
LLVM Workshop Osaka Umeda, Japan
LLVM Workshop Osaka Umeda, JapanLLVM Workshop Osaka Umeda, Japan
LLVM Workshop Osaka Umeda, Japan
 
Presentation about arrays
Presentation about arraysPresentation about arrays
Presentation about arrays
 
QB_DCE_Anuj part 2
QB_DCE_Anuj part 2QB_DCE_Anuj part 2
QB_DCE_Anuj part 2
 
OOP in Rust
OOP in RustOOP in Rust
OOP in Rust
 
Pratikum 2 urai wira s
Pratikum 2 urai wira sPratikum 2 urai wira s
Pratikum 2 urai wira s
 
Pratikum 1 hardiansyah
Pratikum 1 hardiansyahPratikum 1 hardiansyah
Pratikum 1 hardiansyah
 
FOSS4G Europe 2015: OL3-Cesium (3D for OpenLayers)
FOSS4G Europe 2015: OL3-Cesium (3D for OpenLayers)FOSS4G Europe 2015: OL3-Cesium (3D for OpenLayers)
FOSS4G Europe 2015: OL3-Cesium (3D for OpenLayers)
 
Introduction to rust
Introduction to rustIntroduction to rust
Introduction to rust
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Exercise #22
Exercise #22Exercise #22
Exercise #22
 
Bab 2
Bab 2Bab 2
Bab 2
 
Exercise #8 notes
Exercise #8 notesExercise #8 notes
Exercise #8 notes
 
Python opcodes
Python opcodesPython opcodes
Python opcodes
 

Andere mochten auch (8)

Brighton Hospital Presentation
Brighton Hospital PresentationBrighton Hospital Presentation
Brighton Hospital Presentation
 
No uml
No umlNo uml
No uml
 
2016 1003 GIGAPP Accion de innovacion HackINTEF
2016 1003 GIGAPP Accion de innovacion HackINTEF2016 1003 GIGAPP Accion de innovacion HackINTEF
2016 1003 GIGAPP Accion de innovacion HackINTEF
 
Social Studies Review Final Benchmark Td
Social Studies Review Final Benchmark TdSocial Studies Review Final Benchmark Td
Social Studies Review Final Benchmark Td
 
WSU Pharm 2008 Presentation
WSU Pharm 2008 PresentationWSU Pharm 2008 Presentation
WSU Pharm 2008 Presentation
 
Turning Point Presentation 5.18.07
Turning Point Presentation 5.18.07Turning Point Presentation 5.18.07
Turning Point Presentation 5.18.07
 
Teknopreneurship program
Teknopreneurship programTeknopreneurship program
Teknopreneurship program
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
 

Ähnlich wie 110617 lt

Tugasmatematikakelompok 150715235527-lva1-app6892
Tugasmatematikakelompok 150715235527-lva1-app6892Tugasmatematikakelompok 150715235527-lva1-app6892
Tugasmatematikakelompok 150715235527-lva1-app6892
drayertaurus
 
2. Definite Int. Theory Module-5.pdf
2. Definite Int. Theory Module-5.pdf2. Definite Int. Theory Module-5.pdf
2. Definite Int. Theory Module-5.pdf
RajuSingh806014
 
lesson10-thechainrule034slides-091006133832-phpapp01.pptx
lesson10-thechainrule034slides-091006133832-phpapp01.pptxlesson10-thechainrule034slides-091006133832-phpapp01.pptx
lesson10-thechainrule034slides-091006133832-phpapp01.pptx
JohnReyManzano2
 

Ähnlich wie 110617 lt (20)

Tugasmatematikakelompok 150715235527-lva1-app6892
Tugasmatematikakelompok 150715235527-lva1-app6892Tugasmatematikakelompok 150715235527-lva1-app6892
Tugasmatematikakelompok 150715235527-lva1-app6892
 
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour HadoopOSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
 
Andrei rusu-2013-amaa-workshop
Andrei rusu-2013-amaa-workshopAndrei rusu-2013-amaa-workshop
Andrei rusu-2013-amaa-workshop
 
Tugas matematika kelompok
Tugas matematika kelompokTugas matematika kelompok
Tugas matematika kelompok
 
Tugasmatematikakelompok
TugasmatematikakelompokTugasmatematikakelompok
Tugasmatematikakelompok
 
2. Definite Int. Theory Module-5.pdf
2. Definite Int. Theory Module-5.pdf2. Definite Int. Theory Module-5.pdf
2. Definite Int. Theory Module-5.pdf
 
ASFWS 2012 - Obfuscator, ou comment durcir un code source ou un binaire contr...
ASFWS 2012 - Obfuscator, ou comment durcir un code source ou un binaire contr...ASFWS 2012 - Obfuscator, ou comment durcir un code source ou un binaire contr...
ASFWS 2012 - Obfuscator, ou comment durcir un code source ou un binaire contr...
 
Deep generative model.pdf
Deep generative model.pdfDeep generative model.pdf
Deep generative model.pdf
 
Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''
 
Fast parallelizable scenario-based stochastic optimization
Fast parallelizable scenario-based stochastic optimizationFast parallelizable scenario-based stochastic optimization
Fast parallelizable scenario-based stochastic optimization
 
functions limits and continuity
functions limits and continuityfunctions limits and continuity
functions limits and continuity
 
lesson10-thechainrule034slides-091006133832-phpapp01.pptx
lesson10-thechainrule034slides-091006133832-phpapp01.pptxlesson10-thechainrule034slides-091006133832-phpapp01.pptx
lesson10-thechainrule034slides-091006133832-phpapp01.pptx
 
Clojure night
Clojure nightClojure night
Clojure night
 
Ex algebra (5)
Ex algebra  (5)Ex algebra  (5)
Ex algebra (5)
 
Computer Aided Assessment (CAA) for mathematics
Computer Aided Assessment (CAA) for mathematicsComputer Aided Assessment (CAA) for mathematics
Computer Aided Assessment (CAA) for mathematics
 
Group theory notes
Group theory notesGroup theory notes
Group theory notes
 
24 modelling
24 modelling24 modelling
24 modelling
 
Error control coding bch, reed-solomon etc..
Error control coding   bch, reed-solomon etc..Error control coding   bch, reed-solomon etc..
Error control coding bch, reed-solomon etc..
 
19 trig substitutions-x
19 trig substitutions-x19 trig substitutions-x
19 trig substitutions-x
 
MUMS Opening Workshop - An Overview of Reduced-Order Models and Emulators (ED...
MUMS Opening Workshop - An Overview of Reduced-Order Models and Emulators (ED...MUMS Opening Workshop - An Overview of Reduced-Order Models and Emulators (ED...
MUMS Opening Workshop - An Overview of Reduced-Order Models and Emulators (ED...
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

110617 lt

  • 1. MONAD ON GROOVY == MANADOLOGIE masaki@metabolics.co.jp 2011.06.17 1
  • 2. monad? Haskell monoid continuation ...... 2
  • 3. monad! ( ) Haskell Maybe Monad Groovy (2009/8/30, Gr ) 3
  • 4. example 1 2 S = {2x|x ∈ N, x > 3} (comprehension) x 3 ,2 *x 4
  • 5. groovy way def s(n) { ((0..n) .findAll { it**2 > 3 }) .collect { it*2 } } Groovy , 5
  • 6. example 2 import static hr.helix.monadologie.MonadComprehension.foreach def s(n) {    foreach {        x = takeFrom { 0..n }        guard { x**2 > 3 }        yield { 2*x }    } } 6
  • 7. example 3 def pythags(n) {    foreach {        z = takeFrom { 1..n }        x = takeFrom { 1..z }        y = takeFrom { x..z }        guard { x**2 + y**2 == z**2 }        yield { [x, y, z] }    } } assert pythags(12) == [[3, 4, 5], [6, 8, 10]] 7
  • 9. what’s the point monadologie ? => Collection , 9
  • 10. interface Monad<M> { M unit(Object a) M bind(Closure f) } 10
  • 11. List (!) (List<X> X ) List<X> (X a) = { [a] } // List<Y> (List<X> m, f) = { m.inject([]) { r, e -> r + f(e) } } // // where f s.t. List<Y> f(X x) // f apply [] 11
  • 12. unit, bind bind(m, unit) == m bind(unit(m), f) == f(m) // bind(bind(m, f), g) == bind(m, { bind(f(it), g) }) // 12
  • 13. Groovy ? => List (Collection) , ( ) ... 13
  • 14. Option - (e.g. null) Maybe Groovy safe reference “?.” Either - Reader - Closure Writer - State - STM - memoize, , AST 14
  • 15. , ? ( ) ...:-) 15
  • 16. LT 16