SlideShare a Scribd company logo
State

    2009   6   1   id:hiratara
• State
•         (>>=)   State
(1) (>>=)
Int       State Int Int



      f
Int       State Int Int
f

    Int            State Int Int
∋


    a

          f
    Int            State Int Int




                          ∋
              1           (a+1, 2)
              2           (a+2, 3)
                    ...
              s0          (a+s0, s0+1)
: f 10          2   12




                    1          (11, 2)
         f 10   =   2          (12, 3)
                         ...
                    s0         (10+s0, s0+1)
f



1          (2, 1)
2          (4, 2)
     ...
s0         (s0 × 2, s0)
f



1          (2, 1)
2          (4, 2)
     ...
s0         (s0 × 2, s0)

              (=<<) f
                                            1
1          (3, 2)
                                       2
2          (6, 3)
     ...                           f       2+1 = 3
s0         (s0 × 2 + s0, s0 + 1)
(>>=)

  (State x) >>= f = State $ s -> let (v,s') = x s in runState (f v) s'

State(s0           )         (v(s0), s(s0))
                       ...
(v, s') = (s0 × 2, s0) s = (s × 2, s)
f v = f (s × 2) = (s × 2 + s0, s0 + 1)
(f v) s' = (s × 2 + s0, s0 + 1) s = (s × 2 + s, s + 1)


(s0 × 2, s0) >>= f = (s0 × 2 + s0, s0 + 1)
Int       >>=     State Int Int ∋          (s0 × 2, s0)




                (=<<) f
      f
Int               State Int Int ∋(s0 × 2 + s0, s0 + 1)
(1)

•
                f

• (>>=)             f
(2) get   put
put             get

•                ( return   (>>=) )
        State

• put     get     State
get
•                 State

    •
        (   )

    •
get
•                 State

    •
        (   )

    •

                      → (s0, s0)
get

   get

get = State $ s -> (s,s)




                     → (s0, s0)
put s
•
    State

    •
                  ()

    •         s
put s
•
    State

    •
                  ()

    •         s

                       → put s = ( (), s)
put s
      put

 put s = State $ _ -> ((),s)

Int                 State Int Int
            put

()                   State Int ()

                     → put s = ( (), s)
put s
>>=                      put

   put s = State $ _ -> ((),s)

 Int                  State Int Int
              put
                            (=<<) put
  ()                   State Int ()

                       → put s = ( (), s)
(3)
State

         0   1   1
         1   2   2
         2   3   3
   ...
State

                 0            1                   1
                 1            2                   2
                 2            3                   3
   ...
                                  State Int Int

                         0              (1, 1)
         count       =   1              (2, 2)
                                  ...
                         s0             (s0 + 1, s0+1)
(s0 + 1, s0+1)




                         =
                  State Int Int

            0           (1, 1)
count   =   1           (2, 2)
                  ...
            s0          (s0 + 1, s0+1)
get put
Int                    get ∈ State Int Int

               put
()                           State () Int
  () -> n+1

              return
Int                          State Int Int
put         return         >>=




      Int                                get ∈ State Int Int
                                              >>=
                          put
      ()                                       State () Int
               return . ( ¥() -> n+1 )         >>=


      Int                                      State Int Int
Int           get = (s0, s0) ∈ State Int Int
                                >>=
                put
()              ( (), s0 + 1) ∈ State () Int
      return . ( ¥() -> n+1 )    >>=


Int     ( s0 + 1, s0 + 1) ∈ State Int Int
• >>=

• put   get

• do          put   get
                          State
• runState           evalState


                                           (v(s0), s(s0))
                        runState
  State Int Bool                      Int -> (Bool, Int)
evalState
                                                  Int
                  Int -> Bool
            Int
                                         (Bool, Int)
  Bool

More Related Content

Viewers also liked

Monads in perl
Monads in perlMonads in perl
Monads in perl
Masahiro Honma
 
定理3
定理3定理3
定理3
Masahiro Honma
 
レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)
Masahiro Honma
 
Git入門
Git入門Git入門
Git入門
Masahiro Honma
 
ウヰスキーとPSGI
ウヰスキーとPSGIウヰスキーとPSGI
ウヰスキーとPSGI
Masahiro Honma
 
Stateモナドの解説 前編
Stateモナドの解説 前編Stateモナドの解説 前編
Stateモナドの解説 前編
Masahiro Honma
 
モナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gzモナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gz
Masahiro Honma
 
Hachioji.pm in Machida の LT
Hachioji.pm in Machida の LTHachioji.pm in Machida の LT
Hachioji.pm in Machida の LT
Masahiro Honma
 
すべてが@__kanになる
すべてが@__kanになるすべてが@__kanになる
すべてが@__kanになる
Masahiro Honma
 
Math::Category
Math::CategoryMath::Category
Math::Category
Masahiro Honma
 
TraitとMoose::Role
TraitとMoose::RoleTraitとMoose::Role
TraitとMoose::Role
Masahiro Honma
 
カレーとHokkaidopm
カレーとHokkaidopmカレーとHokkaidopm
カレーとHokkaidopm
Masahiro Honma
 
Arrows in perl
Arrows in perlArrows in perl
Arrows in perl
Masahiro Honma
 
AnyEvent and Plack
AnyEvent and PlackAnyEvent and Plack
AnyEvent and Plack
Masahiro Honma
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
Masahiro Honma
 
Levenshtein Automata
Levenshtein AutomataLevenshtein Automata
Levenshtein Automata
Masahiro Honma
 
Monads in python
Monads in pythonMonads in python
Monads in python
eldariof
 
モナモナ言うモナド入門
モナモナ言うモナド入門モナモナ言うモナド入門
モナモナ言うモナド入門
Masahiro Honma
 
すごいMonad入門
すごいMonad入門すごいMonad入門
すごいMonad入門
真一 北原
 
YAPCレポートの舞台裏
YAPCレポートの舞台裏YAPCレポートの舞台裏
YAPCレポートの舞台裏
Masahiro Honma
 

Viewers also liked (20)

Monads in perl
Monads in perlMonads in perl
Monads in perl
 
定理3
定理3定理3
定理3
 
レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)
 
Git入門
Git入門Git入門
Git入門
 
ウヰスキーとPSGI
ウヰスキーとPSGIウヰスキーとPSGI
ウヰスキーとPSGI
 
Stateモナドの解説 前編
Stateモナドの解説 前編Stateモナドの解説 前編
Stateモナドの解説 前編
 
モナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gzモナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gz
 
Hachioji.pm in Machida の LT
Hachioji.pm in Machida の LTHachioji.pm in Machida の LT
Hachioji.pm in Machida の LT
 
すべてが@__kanになる
すべてが@__kanになるすべてが@__kanになる
すべてが@__kanになる
 
Math::Category
Math::CategoryMath::Category
Math::Category
 
TraitとMoose::Role
TraitとMoose::RoleTraitとMoose::Role
TraitとMoose::Role
 
カレーとHokkaidopm
カレーとHokkaidopmカレーとHokkaidopm
カレーとHokkaidopm
 
Arrows in perl
Arrows in perlArrows in perl
Arrows in perl
 
AnyEvent and Plack
AnyEvent and PlackAnyEvent and Plack
AnyEvent and Plack
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 
Levenshtein Automata
Levenshtein AutomataLevenshtein Automata
Levenshtein Automata
 
Monads in python
Monads in pythonMonads in python
Monads in python
 
モナモナ言うモナド入門
モナモナ言うモナド入門モナモナ言うモナド入門
モナモナ言うモナド入門
 
すごいMonad入門
すごいMonad入門すごいMonad入門
すごいMonad入門
 
YAPCレポートの舞台裏
YAPCレポートの舞台裏YAPCレポートの舞台裏
YAPCレポートの舞台裏
 

Similar to Stateモナドの解説 後編

Ejercicios varios de algebra widmar aguilar
Ejercicios varios de  algebra   widmar aguilarEjercicios varios de  algebra   widmar aguilar
Ejercicios varios de algebra widmar aguilar
Widmar Aguilar Gonzalez
 
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSPSend + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
Filippo Vitale
 
como era... patroa
como era... patroacomo era... patroa
como era... patroa
Onésimo Remígio
 
Bessel functionsoffractionalorder1
Bessel functionsoffractionalorder1Bessel functionsoffractionalorder1
Bessel functionsoffractionalorder1
Chumphol Mahattanakul
 
Communication systems solution manual 5th edition
Communication systems solution manual 5th editionCommunication systems solution manual 5th edition
Communication systems solution manual 5th edition
Tayeen Ahmed
 
Ejercicio 211 del libro de baldor
Ejercicio 211 del libro de baldorEjercicio 211 del libro de baldor
Ejercicio 211 del libro de baldor
Alexis Daniel Landero Herrera
 
Prelude to halide_public
Prelude to halide_publicPrelude to halide_public
Prelude to halide_public
Fixstars Corporation
 
ejercicio 211 del libro de Baldor
ejercicio 211 del libro de Baldorejercicio 211 del libro de Baldor
ejercicio 211 del libro de Baldor
Alexis Daniel Landero Herrera
 
Ejercicio 211 del libro de Baldor
Ejercicio 211 del libro de BaldorEjercicio 211 del libro de Baldor
Ejercicio 211 del libro de Baldor
Alexis Daniel Landero Herrera
 
Playing with State Monad
Playing with State MonadPlaying with State Monad
Playing with State Monad
David Galichet
 
Ejercicios prueba de algebra de la UTN- widmar aguilar
Ejercicios prueba de algebra de la UTN-  widmar aguilarEjercicios prueba de algebra de la UTN-  widmar aguilar
Ejercicios prueba de algebra de la UTN- widmar aguilar
Widmar Aguilar Gonzalez
 
Geurdes Monte Växjö
Geurdes Monte VäxjöGeurdes Monte Växjö
Geurdes Monte Växjö
Richard Gill
 
Grokking Monads in Scala
Grokking Monads in ScalaGrokking Monads in Scala
Grokking Monads in Scala
Tim Dalton
 
ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 4 - ΤΕΛΕΣΤΕΣ και η ΔΟΜΗ ΕΛΕΓΧΟΥ (ΕΚΤΥΠΩΣΗ)
ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 4 - ΤΕΛΕΣΤΕΣ και η ΔΟΜΗ ΕΛΕΓΧΟΥ (ΕΚΤΥΠΩΣΗ)ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 4 - ΤΕΛΕΣΤΕΣ και η ΔΟΜΗ ΕΛΕΓΧΟΥ (ΕΚΤΥΠΩΣΗ)
ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 4 - ΤΕΛΕΣΤΕΣ και η ΔΟΜΗ ΕΛΕΓΧΟΥ (ΕΚΤΥΠΩΣΗ)
Dimitris Psounis
 
Magnet Design - Hollow Cylindrical Conductor
Magnet Design - Hollow Cylindrical ConductorMagnet Design - Hollow Cylindrical Conductor
Magnet Design - Hollow Cylindrical Conductor
Pei-Che Chang
 

Similar to Stateモナドの解説 後編 (15)

Ejercicios varios de algebra widmar aguilar
Ejercicios varios de  algebra   widmar aguilarEjercicios varios de  algebra   widmar aguilar
Ejercicios varios de algebra widmar aguilar
 
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSPSend + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
 
como era... patroa
como era... patroacomo era... patroa
como era... patroa
 
Bessel functionsoffractionalorder1
Bessel functionsoffractionalorder1Bessel functionsoffractionalorder1
Bessel functionsoffractionalorder1
 
Communication systems solution manual 5th edition
Communication systems solution manual 5th editionCommunication systems solution manual 5th edition
Communication systems solution manual 5th edition
 
Ejercicio 211 del libro de baldor
Ejercicio 211 del libro de baldorEjercicio 211 del libro de baldor
Ejercicio 211 del libro de baldor
 
Prelude to halide_public
Prelude to halide_publicPrelude to halide_public
Prelude to halide_public
 
ejercicio 211 del libro de Baldor
ejercicio 211 del libro de Baldorejercicio 211 del libro de Baldor
ejercicio 211 del libro de Baldor
 
Ejercicio 211 del libro de Baldor
Ejercicio 211 del libro de BaldorEjercicio 211 del libro de Baldor
Ejercicio 211 del libro de Baldor
 
Playing with State Monad
Playing with State MonadPlaying with State Monad
Playing with State Monad
 
Ejercicios prueba de algebra de la UTN- widmar aguilar
Ejercicios prueba de algebra de la UTN-  widmar aguilarEjercicios prueba de algebra de la UTN-  widmar aguilar
Ejercicios prueba de algebra de la UTN- widmar aguilar
 
Geurdes Monte Växjö
Geurdes Monte VäxjöGeurdes Monte Växjö
Geurdes Monte Växjö
 
Grokking Monads in Scala
Grokking Monads in ScalaGrokking Monads in Scala
Grokking Monads in Scala
 
ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 4 - ΤΕΛΕΣΤΕΣ και η ΔΟΜΗ ΕΛΕΓΧΟΥ (ΕΚΤΥΠΩΣΗ)
ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 4 - ΤΕΛΕΣΤΕΣ και η ΔΟΜΗ ΕΛΕΓΧΟΥ (ΕΚΤΥΠΩΣΗ)ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 4 - ΤΕΛΕΣΤΕΣ και η ΔΟΜΗ ΕΛΕΓΧΟΥ (ΕΚΤΥΠΩΣΗ)
ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 4 - ΤΕΛΕΣΤΕΣ και η ΔΟΜΗ ΕΛΕΓΧΟΥ (ΕΚΤΥΠΩΣΗ)
 
Magnet Design - Hollow Cylindrical Conductor
Magnet Design - Hollow Cylindrical ConductorMagnet Design - Hollow Cylindrical Conductor
Magnet Design - Hollow Cylindrical Conductor
 

Recently uploaded

Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 

Recently uploaded (20)

Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 

Stateモナドの解説 後編

  • 1. State 2009 6 1 id:hiratara
  • 2. • State • (>>=) State
  • 4. Int State Int Int f Int State Int Int
  • 5. f Int State Int Int ∋ a f Int State Int Int ∋ 1 (a+1, 2) 2 (a+2, 3) ... s0 (a+s0, s0+1)
  • 6. : f 10 2 12 1 (11, 2) f 10 = 2 (12, 3) ... s0 (10+s0, s0+1)
  • 7. f 1 (2, 1) 2 (4, 2) ... s0 (s0 × 2, s0)
  • 8. f 1 (2, 1) 2 (4, 2) ... s0 (s0 × 2, s0) (=<<) f 1 1 (3, 2) 2 2 (6, 3) ... f 2+1 = 3 s0 (s0 × 2 + s0, s0 + 1)
  • 9. (>>=) (State x) >>= f = State $ s -> let (v,s') = x s in runState (f v) s' State(s0 ) (v(s0), s(s0)) ... (v, s') = (s0 × 2, s0) s = (s × 2, s) f v = f (s × 2) = (s × 2 + s0, s0 + 1) (f v) s' = (s × 2 + s0, s0 + 1) s = (s × 2 + s, s + 1) (s0 × 2, s0) >>= f = (s0 × 2 + s0, s0 + 1)
  • 10. Int >>= State Int Int ∋ (s0 × 2, s0) (=<<) f f Int State Int Int ∋(s0 × 2 + s0, s0 + 1)
  • 11. (1) • f • (>>=) f
  • 12. (2) get put
  • 13. put get • ( return (>>=) ) State • put get State
  • 14. get • State • ( ) •
  • 15. get • State • ( ) • → (s0, s0)
  • 16. get get get = State $ s -> (s,s) → (s0, s0)
  • 17. put s • State • () • s
  • 18. put s • State • () • s → put s = ( (), s)
  • 19. put s put put s = State $ _ -> ((),s) Int State Int Int put () State Int () → put s = ( (), s)
  • 20. put s >>= put put s = State $ _ -> ((),s) Int State Int Int put (=<<) put () State Int () → put s = ( (), s)
  • 21. (3)
  • 22. State 0 1 1 1 2 2 2 3 3 ...
  • 23. State 0 1 1 1 2 2 2 3 3 ... State Int Int 0 (1, 1) count = 1 (2, 2) ... s0 (s0 + 1, s0+1)
  • 24. (s0 + 1, s0+1) = State Int Int 0 (1, 1) count = 1 (2, 2) ... s0 (s0 + 1, s0+1)
  • 26. Int get ∈ State Int Int put () State () Int () -> n+1 return Int State Int Int
  • 27. put return >>= Int get ∈ State Int Int >>= put () State () Int return . ( ¥() -> n+1 ) >>= Int State Int Int
  • 28. Int get = (s0, s0) ∈ State Int Int >>= put () ( (), s0 + 1) ∈ State () Int return . ( ¥() -> n+1 ) >>= Int ( s0 + 1, s0 + 1) ∈ State Int Int
  • 29. • >>= • put get • do put get State
  • 30. • runState evalState (v(s0), s(s0)) runState State Int Bool Int -> (Bool, Int) evalState Int Int -> Bool Int (Bool, Int) Bool