SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
Formal Methods Forum

                        Type Class in Coq
                                    @tmiya

                                  April 20,2011




@tmiya : Type Class in Coq,                          1
Polymorphism

Polymorphism

      “On Understanding Types, Data Abstraction, and Polymorphism”
      (Cardelli and Wegner, 1985)
              http://lucacardelli.name/Papers/Onunderstanding.a4.Pdf
              polymorphism =
                • universal:
                              parametric : ML
                              inclusion :
                  • ad-hoc:
                              overloading :            Haskell   Type
                              class overloading
                              coercion :




@tmiya : Type Class in Coq,                                             2
Monad




                                       — from

      Hask          : Haskell
              Hask            :               =              =       id=
              Hask                            m:                 return       fmap
                                                             (                       )
              Hask                       Hask                             =
                                                             = return, fmap
                         fmap f
              ma                  KS          / mb
               O                                 O
       return                          fmap         return

                a                              /b
                              f

@tmiya : Type Class in Coq,                                                              3
Monad

                     (1)(2)
      bind (return’ a) f = f a                   µ ◦ ηT = 1T
                     bind(·)return
               ma             AI     / ma
                O                      >     T@
                                              @@
                                   }}}         @@
                                                @@
                                  }              @   @@
                                                     @@
                                }}
                      bind
                              }}                       @@
                                                       @@
                             }                           @@
                                                         @@
                           }}               ηT
                                                           @@
                                                           @@
                        }}} return                           @@
                                                             @@
                      }}                                       @@
                                                               @@
                    }}                           
                a                       a    T2                  /T
                                                      µ
      bind ma return’ = ma                   µ ◦ T η = 1T
                         bind(·)f                      Tη
               ma                   / mb
                                   BJ                           / T2
                O                   |
                                             T@
                                              @@
                                   |           @@
                                                @@
                                 ||              @   @@
                                                     @@
                               ||
                      bind
                              |                        @@
                                                       @@
                            ||                           @@
                                                         @@           µ
                          || f                             @@
       return
                         |                                 @@
                                                             @@
                                                             @@
                       ||                                      @@
                                                               @@
                    |||                                           
                a                       b                        T
@tmiya : Type Class in Coq,                                               4
Monad

                     (3)

        bind (bind ma f) g                                       µ ◦ µT
      = bind ma (fun a = bind (f a) g)                        = µ ◦ Tµ
                         bind(·)f         bind(·)g                     µT
               ma                 /                   / mc     T3           / T2
                O                p7 mb                 7
                               pp                  ppp
                          ppppp              ppppp                                µ
                       ppp f             ppp g
       return                                                 Tµ
                    ppp               ppp                                    
                a                        b                c    T2           /T
                                                                       µ
                              bind(·)(λa.bind(f (a))g )
                                                       /-
               ma                 o7 mb           g gg3 mc
                                            bind(·)gg
                           f ooooo    gggg  ggggg
                         ooo ggggg
                      ooo ggggg λa.bind(f (a))g
                a   go ggg
                    og
                                                          c



@tmiya : Type Class in Coq,                                                           5
Monad         M:Type-Type (   : M = option)
                A             M A
                                                      Haskell
                      Coq

      Class Monad (M:Type - Type):Type := {
        return’ : forall {A}, A - M A;
        bind : forall {A B}, M A - (A - M B) - M B;
        left_unit : forall A B (a:A)(f:A - M B),
          bind (return’ a) f = f a;
        right_unit : forall A (ma:M A),
          bind ma return’ = ma;
        assoc : forall A B C (ma:M A)(f:A-M B)(g:B-M C),
          bind (bind ma f) g = bind ma (fun a = bind (f a) g)
      }.

@tmiya : Type Class in Coq,                                          6
Haskell



      Haskell                 =   do

      Notation m = f := (bind m f)
        (left associativity, at level 49).
      Notation ’do’ a - e ; c := (e = (fun a = c))
        (at level 59, right associativity).




@tmiya : Type Class in Coq,                                7
Identity
                               Identity
      M = id’ : A - A
                              (                  )
                              Qed.        Defined.
      Definition id’(A:Type):Type := A.

      Instance Identity : Monad id’ := {
        return’ A a := a;
        bind A B ma f := f ma
      }.
      Proof.
      (*           *)
      Defined.


@tmiya : Type Class in Coq,                          8
Maybe
      M = option : A - option A Maybe
      return’, bind
      Instance Maybe : Monad option := {
        return’ A a := Some a;
        bind A B ma f :=
          match ma with
          | None = None
          | Some a = f a
          end
      }.
      Proof.
      (*           *)
      Defined.


@tmiya : Type Class in Coq,                9
Maybe




      Eval compute in (None = (fun x = Some (x + 1))).
      Eval compute in (Some 1 = (fun x = Some (x + 1))).




@tmiya : Type Class in Coq,                                   10
List
      List                         flat_map
                              (Hint: xs       ++
      app_ass                   )
      Require Import List.

      Lemma flat_map_app : forall (A B:Type)
        (xs ys:list A)(f:A - list B),
        flat_map f (xs++ys) = flat_map f xs ++ flat_map f ys.

      Instance List : Monad list := {
       return’ A x := x :: nil;
       bind A B m f := flat_map f m
      }.


@tmiya : Type Class in Coq,                                     11
MonadPlus

      Monad                   MonadPlus

      Class MonadPlus (M:Type - Type) : Type := {
        monad : Monad M ;
        (* MonadPlus                *)
      }.

      OO                          Coq     substructure
      (=               ?)
      MonadPlus    Monad     monoid       (monoid        mzero
             mplus)               bind         mzero
      (mzero = 0, mplus = +, bind=×          )



@tmiya : Type Class in Coq,                                      12
MonadPlus
      Class MonadPlus (M:Type - Type) : Type := {
       monad : Monad M ;
       mzero : forall A, M A;
       mplus : forall A, M A - M A - M A;
       mzero_left : forall A f, bind (@mzero A) f = (@mzero A);
       mzero_right : forall A B (ma:M A),
        bind ma (fun x = (@mzero B)) = (@mzero B);
       monoid_left_unit : forall A (ma:M A),
        mplus _ (@mzero A) ma = ma;
       monoid_right_unit : forall A (ma:M A),
        mplus _ ma (@mzero A) = ma;
       monoid_assoc : forall A (ma mb mc:M A),
        mplus _ (mplus _ ma mb) mc = mplus _ ma (mplus _ mb mc)
      }.

@tmiya : Type Class in Coq,                                  13
MaybePlus

        Maybe         MaybePlus
      Instance MaybePlus : MonadPlus option := {
       monad := Maybe;
       mzero A := @None A;
       mplus A m1 m2 :=
         match m1 with
         | None = m2
         | Some x = m1
         end
      }.
      Proof.
      (*         *)
      Defined.

@tmiya : Type Class in Coq,                        14
ListPlus




      List                       ListPlus
                              app_nil_end, app_ass




@tmiya : Type Class in Coq,                          15
A                       R       A
           (CPS)

      Definition cont (R A:Type):Type := (A-R)-R.

      R                       False



      Require Import Logic.FunctionalExtensionality.




@tmiya : Type Class in Coq,                            16
Instance Cont R : Monad (cont R) := {
        return’ A a := fun k:A-R = k a;
        bind A B m f := fun k:B-R = m (fun a = f a k)
      }.
      Proof.
      (* left_unit *)
      intros A B a f. unfold cont in *.
      erewrite - eta_expansion. reflexivity.
      (* right_unit *)
      intros A ma. unfold cont in *.
      erewrite eta_expansion. extensionality x.
      erewrite - eta_expansion. auto.
      (* assoc *)
      intros A B C ma f g. reflexivity.
      Defined.
@tmiya : Type Class in Coq,                                17

Más contenido relacionado

Más de tmiya

Coq Tutorial
Coq TutorialCoq Tutorial
Coq Tutorialtmiya
 
RegExp20110305
RegExp20110305RegExp20110305
RegExp20110305tmiya
 
Coq Party 20101127
Coq Party 20101127Coq Party 20101127
Coq Party 20101127tmiya
 
Maude20100719
Maude20100719Maude20100719
Maude20100719tmiya
 
Formal methods20100529
Formal methods20100529Formal methods20100529
Formal methods20100529tmiya
 
Coq 20100208a
Coq 20100208aCoq 20100208a
Coq 20100208atmiya
 

Más de tmiya (6)

Coq Tutorial
Coq TutorialCoq Tutorial
Coq Tutorial
 
RegExp20110305
RegExp20110305RegExp20110305
RegExp20110305
 
Coq Party 20101127
Coq Party 20101127Coq Party 20101127
Coq Party 20101127
 
Maude20100719
Maude20100719Maude20100719
Maude20100719
 
Formal methods20100529
Formal methods20100529Formal methods20100529
Formal methods20100529
 
Coq 20100208a
Coq 20100208aCoq 20100208a
Coq 20100208a
 

Último

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
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 Pakistandanishmna97
 
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 AmsterdamUiPathCommunity
 
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 WoodJuan lago vázquez
 
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 challengesrafiqahmad00786416
 
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 educationjfdjdjcjdnsjd
 
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 WorkerThousandEyes
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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 FMESafe Software
 
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 SavingEdi Saputra
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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...apidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 

Último (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
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
 
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
 
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
 
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
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+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...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

Typeclass

  • 1. Formal Methods Forum Type Class in Coq @tmiya April 20,2011 @tmiya : Type Class in Coq, 1
  • 2. Polymorphism Polymorphism “On Understanding Types, Data Abstraction, and Polymorphism” (Cardelli and Wegner, 1985) http://lucacardelli.name/Papers/Onunderstanding.a4.Pdf polymorphism = • universal: parametric : ML inclusion : • ad-hoc: overloading : Haskell Type class overloading coercion : @tmiya : Type Class in Coq, 2
  • 3. Monad — from Hask : Haskell Hask : = = id= Hask m: return fmap ( ) Hask Hask = = return, fmap fmap f ma KS / mb O O return fmap return a /b f @tmiya : Type Class in Coq, 3
  • 4. Monad (1)(2) bind (return’ a) f = f a µ ◦ ηT = 1T bind(·)return ma AI / ma O > T@ @@ }}} @@ @@ } @ @@ @@ }} bind }} @@ @@ } @@ @@ }} ηT @@ @@ }}} return @@ @@ }} @@ @@ }} a a T2 /T µ bind ma return’ = ma µ ◦ T η = 1T bind(·)f Tη ma / mb BJ / T2 O | T@ @@ | @@ @@ || @ @@ @@ || bind | @@ @@ || @@ @@ µ || f @@ return | @@ @@ @@ || @@ @@ ||| a b T @tmiya : Type Class in Coq, 4
  • 5. Monad (3) bind (bind ma f) g µ ◦ µT = bind ma (fun a = bind (f a) g) = µ ◦ Tµ bind(·)f bind(·)g µT ma / / mc T3 / T2 O p7 mb 7 pp ppp ppppp ppppp µ ppp f ppp g return Tµ ppp ppp a b c T2 /T µ bind(·)(λa.bind(f (a))g ) /- ma o7 mb g gg3 mc bind(·)gg f ooooo gggg ggggg ooo ggggg ooo ggggg λa.bind(f (a))g a go ggg og c @tmiya : Type Class in Coq, 5
  • 6. Monad M:Type-Type ( : M = option) A M A Haskell Coq Class Monad (M:Type - Type):Type := { return’ : forall {A}, A - M A; bind : forall {A B}, M A - (A - M B) - M B; left_unit : forall A B (a:A)(f:A - M B), bind (return’ a) f = f a; right_unit : forall A (ma:M A), bind ma return’ = ma; assoc : forall A B C (ma:M A)(f:A-M B)(g:B-M C), bind (bind ma f) g = bind ma (fun a = bind (f a) g) }. @tmiya : Type Class in Coq, 6
  • 7. Haskell Haskell = do Notation m = f := (bind m f) (left associativity, at level 49). Notation ’do’ a - e ; c := (e = (fun a = c)) (at level 59, right associativity). @tmiya : Type Class in Coq, 7
  • 8. Identity Identity M = id’ : A - A ( ) Qed. Defined. Definition id’(A:Type):Type := A. Instance Identity : Monad id’ := { return’ A a := a; bind A B ma f := f ma }. Proof. (* *) Defined. @tmiya : Type Class in Coq, 8
  • 9. Maybe M = option : A - option A Maybe return’, bind Instance Maybe : Monad option := { return’ A a := Some a; bind A B ma f := match ma with | None = None | Some a = f a end }. Proof. (* *) Defined. @tmiya : Type Class in Coq, 9
  • 10. Maybe Eval compute in (None = (fun x = Some (x + 1))). Eval compute in (Some 1 = (fun x = Some (x + 1))). @tmiya : Type Class in Coq, 10
  • 11. List List flat_map (Hint: xs ++ app_ass ) Require Import List. Lemma flat_map_app : forall (A B:Type) (xs ys:list A)(f:A - list B), flat_map f (xs++ys) = flat_map f xs ++ flat_map f ys. Instance List : Monad list := { return’ A x := x :: nil; bind A B m f := flat_map f m }. @tmiya : Type Class in Coq, 11
  • 12. MonadPlus Monad MonadPlus Class MonadPlus (M:Type - Type) : Type := { monad : Monad M ; (* MonadPlus *) }. OO Coq substructure (= ?) MonadPlus Monad monoid (monoid mzero mplus) bind mzero (mzero = 0, mplus = +, bind=× ) @tmiya : Type Class in Coq, 12
  • 13. MonadPlus Class MonadPlus (M:Type - Type) : Type := { monad : Monad M ; mzero : forall A, M A; mplus : forall A, M A - M A - M A; mzero_left : forall A f, bind (@mzero A) f = (@mzero A); mzero_right : forall A B (ma:M A), bind ma (fun x = (@mzero B)) = (@mzero B); monoid_left_unit : forall A (ma:M A), mplus _ (@mzero A) ma = ma; monoid_right_unit : forall A (ma:M A), mplus _ ma (@mzero A) = ma; monoid_assoc : forall A (ma mb mc:M A), mplus _ (mplus _ ma mb) mc = mplus _ ma (mplus _ mb mc) }. @tmiya : Type Class in Coq, 13
  • 14. MaybePlus Maybe MaybePlus Instance MaybePlus : MonadPlus option := { monad := Maybe; mzero A := @None A; mplus A m1 m2 := match m1 with | None = m2 | Some x = m1 end }. Proof. (* *) Defined. @tmiya : Type Class in Coq, 14
  • 15. ListPlus List ListPlus app_nil_end, app_ass @tmiya : Type Class in Coq, 15
  • 16. A R A (CPS) Definition cont (R A:Type):Type := (A-R)-R. R False Require Import Logic.FunctionalExtensionality. @tmiya : Type Class in Coq, 16
  • 17. Instance Cont R : Monad (cont R) := { return’ A a := fun k:A-R = k a; bind A B m f := fun k:B-R = m (fun a = f a k) }. Proof. (* left_unit *) intros A B a f. unfold cont in *. erewrite - eta_expansion. reflexivity. (* right_unit *) intros A ma. unfold cont in *. erewrite eta_expansion. extensionality x. erewrite - eta_expansion. auto. (* assoc *) intros A B C ma f g. reflexivity. Defined. @tmiya : Type Class in Coq, 17