SlideShare una empresa de Scribd logo
1 de 16
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

「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
 

La actualidad más candente (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
 

Destacado (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
 

Similar a 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
 

Similar a 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...
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
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
 
"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 ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

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