synthesis of distributed mobile programs using monadic
play

Synthesis of distributed mobile programs using monadic types in Coq - PowerPoint PPT Presentation

Synthesis of distributed mobile programs using monadic types in Coq Marino Miculan Marco Paviotti Dept. of Mathematics and Computer Science University of Udine ITP 2012 August 13th, 2012 1 / 22 The problem The extraction of certified


  1. Synthesis of distributed mobile programs using monadic types in Coq Marino Miculan Marco Paviotti Dept. of Mathematics and Computer Science University of Udine ITP 2012 August 13th, 2012 1 / 22

  2. The problem The extraction of certified functional and effect-free programs is a well-know practice in the field of Type Theory, however: ✔ There are many other computational effects (and corresponding Type Theories, possibly) ✔ These scenarios would greatly benefit from a mechanisms for extraction ✘ Languages implementing these aspects usually do not support the Curry-Howard isomorphism ✘ Implementing a specific proof-assistant would be a daunting task anyway. 2 / 22

  3. Our contribution We propose: • a general methodology for circumventing this problem using the existing technology (Coq) + encapsulate non-functional aspects in monadic types + implement a post-extraction compiler for realizing monadic constructors in the target language • example: distributed programs with effects in Erlang. 3 / 22

  4. A general methodology Step 1: Type Theory Encode a given Type theory with effects in Coq Step 2: Define a Monad in Coq cover- < > ing the computational aspects CiC Sets + Monadic Types Step 3 : Prove the soundness theo- Extraction rem Functional Code (e.g Use the Extraction fa- Step 4: Haskell) with compu- cility to get the func- tional code Define the translation tational annotations function E � � 4 / 22

  5. A general methodology Step 1: Type Theory Encode a given Type theory with effects in Coq Step 2: Define a Monad in Coq cover- < > ing the computational aspects CiC Sets + Monadic Types Step 3 : Prove the soundness theo- Extraction rem Functional Code (e.g Use the Extraction fa- Step 4: Haskell) with compu- cility to get the func- tional code Define the translation tational annotations function E � � 4 / 22

  6. A general methodology Step 1: Type Theory Encode a given Type theory with effects in Coq Step 2: Define a Monad in Coq cover- < > ing the computational aspects CiC Sets + Monadic Types Step 3 : Prove the soundness theo- Extraction rem Functional Code (e.g Use the Extraction fa- Step 4: Haskell) with compu- cility to get the func- tional code Define the translation tational annotations function E � � 4 / 22

  7. A general methodology Step 1: Type Theory Encode a given Type theory with effects in Coq Step 2: Define a Monad in Coq cover- < > ing the computational aspects CiC Sets + Monadic Types Step 3 : Prove the soundness theo- Extraction rem Functional Code (e.g Use the Extraction fa- Step 4: Haskell) with compu- cility to get the func- tional code Define the translation tational annotations function E � � 4 / 22

  8. A general methodology Step 1: Type Theory Encode a given Type theory with effects in Coq Step 2: Define a Monad in Coq cover- < > ing the computational aspects CiC Sets + Monadic Types Step 3 : Prove the soundness theo- Extraction rem Functional Code (e.g Use the Extraction fa- Step 4: Haskell) with compu- cility to get the func- tional code Define the translation tational annotations function E � � 4 / 22

  9. A general methodology Step 1: Type Theory Encode a given Type theory with effects in Coq Step 2: Define a Monad in Coq cover- < > ing the computational aspects CiC Sets + Monadic Types Step 3 : Prove the soundness theo- Extraction rem Functional Code (e.g Use the Extraction fa- Step 4: Haskell) with compu- cility to get the func- tional code Define the translation tational annotations function E � � 4 / 22

  10. A general methodology Step 1: Type Theory Encode a given Type theory with effects in Coq Step 2: Define a Monad in Coq cover- < > ing the computational aspects CiC Sets + Monadic Types Step 3 : Prove the soundness theo- Extraction rem Functional Code (e.g Use the Extraction fa- Step 4: Haskell) with compu- cility to get the func- tional code Define the translation tational annotations function E � � 4 / 22

  11. A general methodology Step 1: Type Theory Encode a given Type theory with effects in Coq Step 2: Define a Monad in Coq cover- < > ing the computational aspects CiC Sets + Monadic Types Step 3 : Prove the soundness theo- Extraction rem Functional Code (e.g Use the Extraction fa- Step 4: Haskell) with compu- cility to get the func- tional code Define the translation tational annotations function E � � E � � Target Code 4 / 22

  12. A general methodology Step 1: Type Theory Encode a given Type theory with effects in Coq Step 2: Define a Monad in Coq cover- < > ing the computational aspects CiC Sets + Monadic Types Step 3 : Prove the soundness theo- Extraction rem Functional Code (e.g Use the Extraction fa- Step 4: Haskell) with compu- cility to get the func- tional code Define the translation tational annotations function E � � E � � Target Code 4 / 22

  13. A general methodology Step 1: Type Theory Encode a given Type theory with effects in Coq Step 2: Define a Monad in Coq cover- < > ing the computational aspects CiC Sets + Monadic Types Step 3 : Prove the soundness theo- Extraction rem Functional Code (e.g Use the Extraction fa- Step 4: Haskell) with compu- cility to get the func- tional code Define the translation tational annotations function E � � E � � Target Code 4 / 22

  14. Extraction of distributed code We define the distributed monad in the Calculus of Inductive Constructions forall w: World and A: Set IO w A :Set 5 / 22

  15. Extraction of distributed code We define the distributed monad in the Calculus of Inductive Constructions forall w: World and A: Set IO w A :Set A computation localized on the specified host 5 / 22

  16. Extraction of distributed code We define the distributed monad in the Calculus of Inductive Constructions forall w: World and A: Set IO w A :Set By Curry-Howard Isomorphism, the (constructive) proofs of these specifications are turned into decorated Haskell code Extraction ⇒ IO w A H 5 / 22

  17. Extraction of distributed code We define the distributed monad in the Calculus of Inductive Constructions forall w: World and A: Set IO w A :Set By Curry-Howard Isomorphism, the (constructive) proofs of these specifications are turned into decorated Haskell code Extraction ⇒ IO w A H These decorations are exploited by the Haskell- Erlang Compiler E � � : H → E 5 / 22

  18. Extraction of distributed code We define the distributed monad in the Calculus of Inductive Constructions forall w: World and A: Set IO w A :Set By Curry-Howard Isomorphism, the (constructive) proofs of these specifications are turned into decorated Haskell code Extraction ⇒ IO w A H These decorations are exploited by the Haskell- Erlang Compiler E � � : H → E Haskell Erlang dis- annotated code tributed code 5 / 22

  19. Monads in Coq We define a family of monads indexed by worlds from Set to Set . Given a world w a monad is a functor defined as IO w A = S → (( R w A ) + Error ) 6 / 22

  20. Monads in Coq We define a family of monads indexed by worlds from Set to Set . Given a world w a monad is a functor defined as IO w A = S → (( R w A ) + Error ) A Localized com- putation 6 / 22

  21. Monads in Coq We define a family of monads indexed by worlds from Set to Set . Given a world w a monad is a functor defined as IO w A = S → (( R w A ) + Error ) Function Space from the global store to the results plus the error state 6 / 22

  22. Monads in Coq We define a family of monads indexed by worlds from Set to Set . Given a world w a monad is a functor defined as IO w A = S → (( R w A ) + Error ) Monadic Operators IOget w A : IO remote A → IO w A λ κ σ. κ ( σ ) (Operator’s implementation) 6 / 22

  23. Monads in Coq We define a family of monads indexed by worlds from Set to Set . Given a world w a monad is a functor defined as IO w A = S → (( R w A ) + Error ) Monadic Operators IOget w A : IO remote A → IO w A λ κ σ. κ ( σ ) (Operator’s implementation) Other monadic operators IOreturn w A : A → IO w A IObind w A B : IO w A → ( A → IO w B ) → IO w B IOlookup w A : Ref w → ( N → IO w A ) → IO w A IOupdate w A : Ref w → N → IO w A → IO w A IOnew w A : N → ( Ref w → IO w A ) → IO w A 6 / 22

  24. Extraction Lemma (Remote Procedure Call) ∀ w w’ , ( N → IO w’ bool ) → ( N → IO w bool ) Proof. simpl; introv f. intro n. apply* IOget. Qed . Haskell iOget w w’ (f n) rpc w w’ f n = 7 / 22

  25. Extraction Lemma (Remote Procedure Call) ∀ w w’ , ( N → IO w’ bool ) → ( N → IO w bool ) Proof. simpl; introv f. intro n. apply* IOget. Given two worlds w w’ Qed . Haskell iOget w w’ (f n) rpc w w’ f n = 7 / 22

  26. Extraction Lemma (Remote Procedure Call) ∀ w w’ , ( N → IO w’ bool ) → ( N → IO w bool ) Proof. simpl; introv f. intro n. apply* IOget. Qed . Given a function f Haskell iOget w w’ (f n) rpc w w’ f n = 7 / 22

  27. Extraction Lemma (Remote Procedure Call) ∀ w w’ , ( N → IO w’ bool ) → ( N → IO w bool ) Proof. simpl; introv f. intro n. apply* IOget. Given a value, say n Qed . Haskell iOget w w’ (f n) rpc w w’ f n = 7 / 22

Recommend


More recommend