
Type Systems and Programming D. Renault ENSEIRB-Matmeca Mar. 24th 2021, v.1.4.4 Introduction What’s a programming language ? int ackermann(int m, int n) { ackermann { if (!m) return n + 1; 0=1⊃!:1+2⊃! if (!n) return ackermann(m-1,1); 0=2⊃!:r(¯1+1⊃!)1 return ackermann(m-1, r(¯1+1⊃!),r(1⊃!),¯1+2⊃! ackermann(m,n-1)); } } A complex and expressive tool for the representation of computations. D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 2 / 122 Introduction Focus on the problem of the verification of these computations. What properties can one expect to be enforceable ? Termination properties : is it possible to be perfectly certain that a given program evaluates in a finite number of steps ? Correctness properties : is it possible to be perfectly certain that a program never ends up in an uncontrolled error state ? And more pragmatically, checking for the presence or absence of : null pointer exceptions, invalid file descriptors, indices out of array bounds, divisions by zero . D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 3 / 122 Introduction How is it possible to enforce some of these properties ? ) Different families of methods, spread along the development cycle. Requirements Deductive methods Formal verification Model Model checking ::: Architecture Lexical analysis Static analysis Implementation Type systems ::: Testing Testing Runtime verification Maintenance Monitoring ::: ) Each family possesses different characteristics : Compile-time or Runtime Automatic or Assisted Decidable (complexity ?) or Semi-decidable D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 4 / 122 Type systems (informal description) a family of tractable methods, considering programs on a syntactic level, verifying some properties on their behaviors. General tactics Classify the expressions occurring inside a program into types, Verify that the combination of these types into the program respect a set of coherence rules. Example : locomotive + flower D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 5 / 122 Programming languages and type systems studied in this course : OCaml (4.09) caml.inria.fr Haskell (ghc-8.10) haskell.org/ghc LiquidHaskell (0.8-git) ucsd-progsys.github.io/liquidhaskell-blog Scala (2.12) scala-lang.org And their influence in mainstream languages : Java 8-15, C++ 14-20, C# 5-9 . D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 6 / 122 Some references Pierce, B. C. Types and Programming Languages. MIT Press, 2002. Bruce, K. B. Foundations of Object-oriented Languages : Types and Semantics. MIT Press, 2002. Hindley, J. R. Basic simple type theory. Cambridge University Press, 1997. Wadler, P. Propositions as types. Communications ACM, 2015. D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 7 / 122 Overview 1 Simple lambda-calculus 2 Polymorphism D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 8 / 122 1 Simple lambda-calculus Propositional logic Untyped lambda calculus Simply typed lambda calculus Type checking and inference Curry-Howard correspondence 2 Polymorphism D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 9 / 122 Definition (Minimal intuitionistic logic) The minimal intuitionistic logic is the set of all formulae P; Q;::: constructed from : an infinite set of atomic formulae denoted as variables α; β; : : : , if P; Q are two formulas, then P ) Q is also a formula. ) ) ) α ) ) ) β δ α β α δ D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 10 / 122 Definition (Sequent) A sequent is an assertion Γ ` α, where : Γ is a possibly empty sequence of formulae called the antecedents, and α is a formula called the consequent. Writing Γ; P ` Q means that the antecedents are constituted of a list of formulae Γ along with a specific formula P. D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 11 / 122 Definition (Derivation tree) A derivation tree (or proof tree) is a tree whose nodes are syntactically coherent with a finite set of inference rules. In propositional logic, these rules are the following : Γ; P ` Q Γ ` P Γ ` P ) Q [ax] [)i] [)e] P ` P Γ ` P ) Q Γ ` Q Each inference rule possesses a name indicating its role, most of the time the introduction (I) or the elimination (E) of a logical operator. D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 12 / 122 Γ ` R Γ ` R ) (S ) T ) Γ ` R Γ ` R ) S Γ ` S ) T Γ ` S Γ ::= f(R ) (S ) T )); (R ) S); Rg ` T (R ) (S ) T )); (R ) S) ` (R ) T ) (R ) (S ) T )) ` (R ) S) ) (R ) T ) Frege’s theorem R ) (S ) T ) ) (R ) S) ) (R ) T ) Inference rules Γ; P ` Q Γ ` P Γ ` P ) Q [ax] [)i] [)e] P ` P Γ ` P ) Q Γ ` Q Proof as a derivation tree ` (R ) (S ) T )) ) ((R ) S) ) (R ) T )) D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 13 / 122 Γ ` R Γ ` R ) (S ) T ) Γ ` R Γ ` R ) S Γ ` S ) T Γ ` S Γ ::= f(R ) (S ) T )); (R ) S); Rg ` T (R ) (S ) T )); (R ) S) ` (R ) T ) Frege’s theorem R ) (S ) T ) ) (R ) S) ) (R ) T ) Inference rules Γ; P ` Q Γ ` P Γ ` P ) Q [ax] [)i] [)e] P ` P Γ ` P ) Q Γ ` Q Proof as a derivation tree (R ) (S ) T )) ` (R ) S) ) (R ) T ) ` (R ) (S ) T )) ) ((R ) S) ) (R ) T )) D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 13 / 122 Γ ` R Γ ` R ) (S ) T ) Γ ` R Γ ` R ) S Γ ` S ) T Γ ` S Γ ::= f(R ) (S ) T )); (R ) S); Rg ` T Frege’s theorem R ) (S ) T ) ) (R ) S) ) (R ) T ) Inference rules Γ; P ` Q Γ ` P Γ ` P ) Q [ax] [)i] [)e] P ` P Γ ` P ) Q Γ ` Q Proof as a derivation tree (R ) (S ) T )); (R ) S) ` (R ) T ) (R ) (S ) T )) ` (R ) S) ) (R ) T ) ` (R ) (S ) T )) ) ((R ) S) ) (R ) T )) D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 13 / 122 Γ ` R Γ ` R ) (S ) T ) Γ ` R Γ ` R ) S Γ ` S ) T Γ ` S Frege’s theorem R ) (S ) T ) ) (R ) S) ) (R ) T ) Inference rules Γ; P ` Q Γ ` P Γ ` P ) Q [ax] [)i] [)e] P ` P Γ ` P ) Q Γ ` Q Proof as a derivation tree Γ ::= f(R ) (S ) T )); (R ) S); Rg ` T (R ) (S ) T )); (R ) S) ` (R ) T ) (R ) (S ) T )) ` (R ) S) ) (R ) T ) ` (R ) (S ) T )) ) ((R ) S) ) (R ) T )) D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 13 / 122 Γ ` R Γ ` R ) (S ) T ) Γ ` R Γ ` R ) S Frege’s theorem R ) (S ) T ) ) (R ) S) ) (R ) T ) Inference rules Γ; P ` Q Γ ` P Γ ` P ) Q [ax] [)i] [)e] P ` P Γ ` P ) Q Γ ` Q Proof as a derivation tree Γ ` S ) T Γ ` S Γ ::= f(R ) (S ) T )); (R ) S); Rg ` T (R ) (S ) T )); (R ) S) ` (R ) T ) (R ) (S ) T )) ` (R ) S) ) (R ) T ) ` (R ) (S ) T )) ) ((R ) S) ) (R ) T )) D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 13 / 122 Γ ` R Γ ` R ) (S ) T ) Frege’s theorem R ) (S ) T ) ) (R ) S) ) (R ) T ) Inference rules Γ; P ` Q Γ ` P Γ ` P ) Q [ax] [)i] [)e] P ` P Γ ` P ) Q Γ ` Q Proof as a derivation tree Γ ` R Γ ` R ) S Γ ` S ) T Γ ` S Γ ::= f(R ) (S ) T )); (R ) S); Rg ` T (R ) (S ) T )); (R ) S) ` (R ) T ) (R ) (S ) T )) ` (R ) S) ) (R ) T ) ` (R ) (S ) T )) ) ((R ) S) ) (R ) T )) D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 13 / 122 Frege’s theorem R ) (S ) T ) ) (R ) S) ) (R ) T ) Inference rules Γ; P ` Q Γ ` P Γ ` P ) Q [ax] [)i] [)e] P ` P Γ ` P ) Q Γ ` Q Proof as a derivation tree Γ ` R Γ ` R ) (S ) T ) Γ ` R Γ ` R ) S Γ ` S ) T Γ ` S Γ ::= f(R ) (S ) T )); (R ) S); Rg ` T (R ) (S ) T )); (R ) S) ` (R ) T ) (R ) (S ) T )) ` (R ) S) ) (R ) T ) ` (R ) (S ) T )) ) ((R ) S) ) (R ) T )) D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 13 / 122 Frege’s theorem R ) (S ) T ) ) (R ) S) ) (R ) T ) Inference rules Γ; P ` Q Γ ` P Γ ` P ) Q [ax] [)i] [)e] P ` P Γ ` P ) Q Γ ` Q Proof as a derivation tree Γ ` R Γ ` R ) (S ) T ) Γ ` R Γ ` R ) S Γ ` S ) T Γ ` S Γ ::= f(R ) (S ) T )); (R ) S); Rg ` T (R ) (S ) T )); (R ) S) ` (R ) T ) (R ) (S ) T )) ` (R ) S) ) (R ) T ) ` (R ) (S ) T )) ) ((R ) S) ) (R ) T )) 3 D. Renault (ENSEIRB-Matmeca) Type Systems and Programming Mar. 24th 2021, v.1.4.4 13 / 122 Summary on propositional logic The model of propositional logic offers : a language describing a family of objects inductively, and a system for defining a subset of this family respecting local rules. The difficulty lies in constructing a kind of proof (here a derivation tree) for assessing the validity of a proposition. In the following, we construct an equivalent model for a programming language : the untyped λ-calculus.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages192 Page
-
File Size-