Next Article in Journal
Yamabe Solitons on Conformal Almost-Contact Complex Riemannian Manifolds with Vertical Torse-Forming Vector Field
Previous Article in Journal
Interval-Valued General Residuated Lattice-Ordered Groupoids and Expanded Triangle Algebras
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

A Sound Definitional Interpreter for a Simply Typed Functional Language

Department of Computer Engineering, Muğla Sıtkı Koçman University, Muğla 48000, Turkey
Axioms 2023, 12(1), 43; https://doi.org/10.3390/axioms12010043
Submission received: 6 September 2022 / Revised: 12 December 2022 / Accepted: 26 December 2022 / Published: 30 December 2022
(This article belongs to the Section Mathematical Analysis)

Abstract

:
In this paper, we develop, in the proof assistant Coq, a definitional interpreter and a type-checker for a simply typed functional language, and formally prove that the mentioned type-checker is sound with respect to the definitional interpreter via progress and preservation. To represent binders, we embark on the choice of “concrete syntax” in which parameters are just names (or strings).

1. Introduction

In the domain of programming language semantics, interpreters [1] constitute the bases for the abstract specification of higher-order programming languages. This specification is simply handled by defining the semantics of an object language in terms of the semantics of a target (or host) language. An interpreter is said to be definitional if it is computational; that is, if it could be executed to test and validate the semantics of the object language programs in the “trusted” target language with well-known semantics. Functional programming languages that support algebraic data types (such as Haskell, OCaml, Coq, etc.), especially those serving dependent types, are suitable targets to implement interpreters. We definitionally formalize small-step operational semantics of a simply typed functional language, a variant of simply typed Lambda calculus ( λ ) [2], alongside a type-checker in the Coq proof assistant [3]. In such an approach, one needs to bridge the interpreter and the type-checker together simply by proving that the type system is sound, potentially embarking on the approach proposed by Wright and Felleisen [4]. In more formal terms, one needs to make sure that the following properties hold.
(i)
If an arbitrarily given term is well-typed, then it either reduces in a single step into some other term or it is already a value. That is, well-typed terms are never stuck;
(ii)
the type of a given term does not vary under reduction/evaluation.
The former property is called progress while the latter is known as preservation. Putting all related technical machinery together and obtaining these proofs even for a not-so-rich object language might very well be tedious and, thus, error-prone. This underpins the main target of the paper, where we carefully investigate and prove the properties (i) and (ii) for a simply typed functional language (extending λ ) both in a pen-and-paper setting and in a Coq formalization. We detail and present technical machinery that constructs those proofs in both contexts and relate one to the other. To the best of the author’s knowledge, such a Coq development does not exist out there with a similar extent of technicality (as well as the approach). Related formalization is not definitional and does not prove the soundness via (i) and (ii).

1.1. Related Work and Contributions

The approach employed by [5,6,7,8] benefits from intrinsically typed abstract syntax definitions when it comes to encoding the object language terms into a dependently typed target language. This way, the type checker of the target language is enabled to automatically verify the safety type of the interpreter. The approach has been extended in [9] such that it supports linearly typed languages as well.
Darais et al. [10,11] studied abstract definitional interpreters written in a monadic style, which makes it possible to capture operations that interact with the outside world. Therefore, languages with impure features (e.g., use of local/global state, mechanisms to handle exceptions, etc.) could also be nicely interpreted. This approach has close relations with that of [12,13,14,15,16] where definitional interpreters mimic state machines, especially non-deterministic pushdown automata.
With all of these mentioned, the main contribution of this paper lies in the Coq formalization of an interpreter for a simply typed language alongside its soundness proof captured by progress and preservation properties. In these lines, novelties are a ’few folded’, as mentioned below:
  • The presented interpreter is implemented to be computational; not living in Coq’s Prop. Amin et al. [17] definitionally implemented a similar interpreter; however, the attached soundness proof was not handled by progress and preservation. Moreover, the approach conducted in Software Foundations [18] and Koprowski’s paper [19] makes use of non-definitional interpreters, living in Coq’s Prop, it, however, obtains soundness proof via progress and preservation. In essence, we combine these approaches.
  • We aimed to have complete literature on the Coq formalization surrounding the definitional interpreters for simply typed languages, alongside [20,21]. We discuss the technical machinery that closes the soundness proof of the interpreter. Even though the main message of the paper is well-known, to the author’s best knowledge, there is no Coq formalization that implements both type-checking and reduction (for some extension of λ ) in a definitional fashion (outside Coq’s Prop), formally relating to one another.
  • Our λ extension involves a ’fixpoint’, branching constructors, and a few binary operations over natural numbers and Booleans.
The Coq formalization already deals with an extension of λ interpreted as a case study. We could make use of the same approach presented here (https://github.com/ekiciburak/Lambda2, accessed on 8 December 2022) (a definitional interpreted for a polymorphically typed functional language coded in Haskell), enriching the current state of our interpreter. The extension is very easily adaptable, as discussed in  [17]; it brings over new cases as part of the soundness and will be targeted in the near future.
In this regard, the milestones of the formalization are explained in Section 2.3Section 2.4 and Section 3 while the whole library is accessible at https://github.com/ekiciburak/extSTLC/tree/master (accessed on 17 December 2020). For the file organization of the library, please refer to Appendix A.

1.2. Organization of the Paper

In Section 2, we first give a quick recap of the untyped Lambda calculus. We then present an extension with natural numbers, Booleans, branching, and fixpoint constructors. Afterward, we introduce a definitional interpreter based on small-step call-by-value semantics, and a type-system employing simple (or non-dependent) types. Along the same lines, we give a taste of such functions in a Coq formalization. In Section 3, we discuss, in deep technical details, the soundness of the type system with respect to the interpretation via both pen-and-paper and Coq-certified proofs.

2. A Quick Recap of the λ Calculus

The λ calculus is a mathematical formalism that expresses computations as function evaluations. It treats functions in an intensional viewpoint in which a function simply is an abstraction composed of input arguments and a body. The equality over functions is syntactically tested in between function bodies modulo renaming (α-equivalence or renaming) of the bound arguments. The principle of functional extensionality cannot be directly proven there but can be taken as an axiom whenever needed. The functions with multiple input arguments can be rewritten as sequences of functions using a single argument. This technique is known as Currying or Schonfinkeling. We now state below the syntax of the λ calculus in an inductive fashion:
t:=xterm variable/identifier
λ x . t function abstraction
t t function application
An abstraction λ x . t is indeed a representation of a function with the bound input argument x and the body t separated by the period ‘.’ symbol. For instance, thinking of a function f ( a ) : = a + 1 , with argument a ranging over natural numbers, one can simply encode it as λ a . a + 1 within the Lambda terms. Here, the Greek letter λ is chosen to anonymously name functions as it does not matter whether to name functions. Thus, all of them are uniquely named λ .
To express a computation within the scope of λ calculus, the function applications of the form t t are employed. It is not possible to evaluate terms under the binder Lambda. Namely, an abstraction alone cannot be evaluated. It is necessary to have an abstraction applied to a term (reducible term or redex) when it comes to speaking of function evaluations:
( λ x . M ) N β M [ x : = N ]
This one step of the evaluation is known as β-reduction and is denoted by the right-arrow with the letter β sub-scripted: ‘ β ’. The β -reduction can be viewed as a single step of the computation in which an application of the form ( λ x . M ) N evaluates or reduces into a term M [ x : = N ] denoting a variant of M in which every occurrence of the argument x is substituted by the applicant term N.
Example 1.
The term ( λ x . x + y ) 10 evaluates in one beta-step into 10 + y . Notice that the variable y here is not bound by the binder Lambda. These kinds of terms in Lambda expressions are known asfree variables.
Example 2
(Church Encoding). It is possible to encode natural numbers in λ calculus in such a way that the term λ f . λ n . f n denotes the natural number 1 while λ f . λ n . f f f n denotes the natural 3. Namely, the number of applications of the term f over the term n defines the corresponding natural number.
Example 3.
Let t : = λ x . λ y . x in 1 t = ( λ f . λ n . f n ) t β λ n . t n = λ n . ( λ x . λ y . x ) n β λ n . ( λ x . λ y . x ) n .
Example 4.
Let Ω : = λ x . x x in Ω Ω = λ x . x x ( λ x . x x ) β Ω Ω β Ω Ω β Ω Ω
Example 5.
There are two ways to beta-reduce the term Ω 1 t : (i) into 1 1 t if the application on the left is accounted for first; (ii) into Ω λ n . t n if the one on the right.
Notice that the expression Ω Ω in Example 4 loops under beta-reduction returning itself. Such an evaluation never reaches a final or termination state. Moreover, the Example 5 aims at presenting the fact that non-deterministic evaluations can also be encoded within the scope of λ calculus. The goal to have them is to informally show that λ calculus is indeed Turing complete. Namely, any computation that could be simulated by a Turing machine could also be implemented within Lambda terms. This conclusion can also be inferred from the famous Church–Turing Thesis but cannot be formally proven as it is not mathematically stated. However, one can disprove it just by refutation. Namely, it suffices for one to come up with a computation that can be simulated with one model but not with the other.

2.1. Evaluation Strategies

In order to impose an order of evaluation for a deterministic reduction of Lambda terms, several strategies are put forward. We discuss in this section, the strategy named call-by-value (CBV) and skip the others as it constitutes a basis for our Coq development. The CBV permits an application to reduce only after reducing its argument into a value. Namely, considering the term e 1 e 2 , CBV ensures that e 2 is fully evaluated until no further reduction steps are possible (into the normal form), and then the application takes place. That could formally be stated as:
isvalue   e 2 = true ( λ x . e 1 ) e 2 β e 1 [ x : = e 2 ]   ( app 1 )   isvalue   e 2 = false   e 2 β e 2 ( λ x . e 1 ) e 2 β ( λ x . e 1 ) e 2   ( app 2 )
such that the isvalue and substitution (denoted ? [ ? : = ? ] ) functions are formally given in Definitions 1 and 2, respectively.
Definition 1.
The isvalue   function is defined as follows:
isvalue ( λ x . e ) true isvalue _ false
Definition 2.
The substitution function is recursively implemented as follows:
Ident x [ s : = v ] if x = s then v else Ident x
( λ x . e ) [ s : = v ] if x s then λ x . e [ s : = v ] else λ x . e

2.2. Extensions

For a more involved calculus, let us now extend the set of Lambda terms, and accordingly, the accompanying evaluation strategy. We drop in natural numbers, Booleans, a technique to handle branching and a fixpoint combinator. Moreover, we include three operations over natural numbers, addition, subtraction, and multiplication, together with a pair of Boolean comparison operators: equality and greater-than checks. The extended set of terms are lsited in Figure 1:
In Figure 2, we extend the CBV strategy, such that it covers the newly introduced terms as well.
Definition 3.
Theisvaluefunction is updated into:
isvalue ( λ x . e ) true
isvalue ( N V a l n ) true
isvalue ( B V a l b ) true
isvalue _ false
Definition 4.
Moreover, the substitution function is extended in the following cases:
( t 1 t 2 ) [ s : = v ] ( t 1 [ s : = v ] ) ( t 2 [ s : = v ] )
( ITE t 1 t 2 t 3 ) [ s : = v ] ITE ( t 1 [ s : = v ] ) ( t 2 [ s : = v ] ) ( t 3 [ s : = v ] )
( Fix t 1 ) [ s : = v ] Fix ( t 1 [ s : = v ] )
( Plus t 1 t 2 ) [ s : = v ] Plus ( t 1 [ s : = v ] ) ( t 2 [ s : = v ] )
( Minus t 1 t 2 ) [ s : = v ] Minus ( t 1 [ s : = v ] ) ( t 2 [ s : = v ] )
( Mult t 1 t 2 ) [ s : = v ] Mult ( t 1 [ s : = v ] ) ( t 2 [ s : = v ] )
( Eq t 1 t 2 ) [ s : = v ] Eq ( t 1 [ s : = v ] ) ( t 2 [ s : = v ] )
( Gt t 1 t 2 ) [ s : = v ] Gt ( t 1 [ s : = v ] ) ( t 2 [ s : = v ] )
( NVal n ) [ s : = v ] NVal n
( BVal b ) [ s : = v ] BVal b
Notice that the symbols ‘+’, ‘−’ and ‘×’ appearing in the conclusions of the rules p l u s 1 , m i n u s 1 , and m u l t 1 are, respectively, denoting addition, subtraction, and multiplication over natural numbers. Similarly, the symbols ‘=’ and ‘>’ used in the conclusions of the rules e q 1 and g t 1 are employed to denote Boolean equality and greater-than checks. The rules to define branching i t e 1 , i t e 2 , and i t e 3 are indeed folklore. The term ITE e 1   e 2   e 3 evaluates in a single step into e 2 if e 1 is the Boolean value true; into e 3 if e 2 is the Boolean false. Otherwise, it reduces to ITE e 1   e 2   e 3 if e 1 evaluates into e 1 . There is a fixpoint combinator Fix that takes a term f and, in a single beta-step, replaces every occurrence of the variable (or identifier) x with the term f itself in e if f is a Lambda term, such as λ x . e . Otherwise, if f is evaluated into f in a single beta-step then the term Fix f reduces into Fix f . The rules governing operations over ’naturals’ and Booleans are also very usual. The term Plus x  y reduces into the natural number a + b (denoted NVal ( a + b )) if x is a natural number a (NVal a) and y is a natural number b (NVal b). If this is not the case, plus x  y evaluates into Plus x  y if x is a value; into Plus x   y, otherwise, given that x reduces to x and y reduces to y in a single step. The other rules concerning subtraction, multiplication, equality, and greater-than checks should be read in the same manner as addition. Note also that the terms that are marked values (by the isvalue function) do not evaluate any further, similar to variables (or identifiers).

2.3. A Type System with a Coq Implementation

Looking back at Example 3 in Section 2, one could easily notice that applying the constant term 1 to the first projection function t makes no sense in a reasonable sort of mathematics. It is possible to make a similar comment for the term Ω in Example 4: self-application might be decently awkward. Therefore, to avoid these kinds of unintended cases, and to prune them out, one may follow a syntactic approach that categorizes terms according to the types of values they compute. This eventually allows for the proof of the fact that there are no more questions about the aforementioned unintended program behaviors. The set of Lambda terms presented in Figure 1, this time, with the typing information injected-in, is listed in Figure 3.
The Lambda binder is indeed the only constructor where typing information appears within the term declarations. This simply is to well-type the input variable of a given Lambda term in the construction phase. The rest of the terms are indeed the same as they are given before in Figure 1. It is not cumbersome to reflect these into a Coq implementation:
Axioms 12 00043 i001
One crucial point to underline is that the type system here allows only for ordinary function/arrow types leaving aside dependent and polymorphic function types. Namely, it is a variant and an extension of the simply typed Lambda calculus; not as expressive as, other calculi in Barendregt’s cube [22], such as System F [23], System F ω nor λ C  [24]. The type system involves two base types Int and Bool with the possibility of inductively constructing “Arrow” types out of them. Notice also that in implementing binders, we embark on the choice of “concrete syntax” due to Church [2], in which the identifiers of Lambda terms are just strings. This choice definitely requires some extra care when it comes to avoid variable capture. See Section 2.4, especially the text following the subst function, for a further explanation. Another point to draw attention to is that the term constructor NVal adds to the set of terms the natural numbers (nat) of Coq. Similarly, the constructor BVal enriches the set of terms with the Coq Booleans (bool).
Let us now take a closer look into the typing judgments, formally stated in Figure 4, which are supposed to govern term evaluations just by allowing well-typed terms to reduce only.
We assume that there exists some context Γ that is interpreted as a list of typing relations, such as x : ϕ , respecting the shadowing property. Namely, if the same variable appears more than once in the context, the leftmost appearance is considered: the one on the left shadows others. For instance, suppose we have a context Γ in the form of [ ( x : ϕ 1 ) : : ( y : ϕ 2 ) : : ( x : ϕ 3 ) ], we consider the type of the instance x to be ϕ 1 not ϕ 3 . Therefore, under some context Γ (denoted “ Γ ? ”), to obtain the type of a given variable x, a lookup (starting from the left end of the context), denoted Γ ( x ) , is employed ( i d t ). Similarly, under some context Γ extended with the fact that some variable x ranging over the type τ 1 , if it is possible to deduce that some term e is of type τ 2 then the Lambda term λ x : τ . e has the arrow type τ 1 τ 2 under the same context Γ ( l a m t ), accordingly denoted Γ , x : t 1 e : t 2 . To apply an arbitrary term e 1 to a term e 2 , one needs to make sure that the former term is of an arrow type such that the domain of this type matches with the type of the latter. Moreover, the application e 1 e 2 is now an instance of e 1 ’s co-domain type ( a p p t ).
If f is a term of some arrow type τ τ , then the term Fix f is thought to be a fix-point f, and must be of type τ ( f i x t ). The term Plus e 1 e 2 is of the base type I n t only if both e 1 and e 2 are of type I n t ( p l u s t ). Similarly, the term Eq e 1 e 2 is of the base type B o o l only if both e 1 and e 2 are of type I n t ( e q t ). Remark also that t : τ denotes the fact that the term t is of type τ under the empty context. In a Coq formalization, we implement the rules stated in Figure 4, using a recursive function named typecheck, as follows: Axioms 12 00043 i002 where the context ctx is a list of string-type pairs which always is extended on the left-hand side to obtain the shadowing property (explained above) satisfied.
Axioms 12 00043 i003
In our implementation, lookups are always performed by/starting from the left end of a given context. This matches with the idea that designates the shadowing feature. The output type of the lookup function is wrapped by the option type (or monad [25]) of Coq, just in case that the input variable is absent from the provided context: the function ends up returning None.
The function typecheck takes a term along with a context, and outputs the type of the term under the input context. Similar to that of the lookup, the instances returned by the typecheck function are also wrapped with the option type so that upon ill-typed inputs, such as App (NVal 5) (BVal false), the function returns None.

2.4. A Definitional Interpreter in Coq

We first adapt the rules stated in Figure 2, such that the typing information explicitly appears in reduction steps. To do so, it suffices to add types to the terms where the Lambda binder is involved as it is the only constructor that embodies syntactical typing information. Therefore, only the rules a p p 3 and a p p 4 are re-designated and presented in Figure 5.
A small-step CBV interpreter based on the typing-adapted versions of the rules (as in Figure 5) stated in Figure 2 is definitionally implemented in Coq as follows: Axioms 12 00043 i004Axioms 12 00043 i005 where the substitution function subst (Definition 4) is formalized to be:
Axioms 12 00043 i006
The point that this interpreter being definitional stems from the fact that it takes a term, and computes in real time a reduced term out of it. This is in fact the point where our interpreter differs from that of ’Software Foundations’ [18] in which interpretation is not computational as it is developed in Coq’s Prop. The return type of the function beta is wrapped by the option type for stuck (see Definition 6) terms, such as App (NVal 5) (BVal false), the  function returns None, meaning no further reduction steps on this term is possible. Notice that we skipped in the above definition the match-cases for operators, such as Minus, Mult, Eq and Gt because they are very similar to that of Plus. Please refer to the accompanying Coq library for the complete definition. Considering the substitution, we implement a function (named subst above) that is capture avoiding but in a restricted form: only to be used in handling beta-reduction of closed terms; namely terms that do not involve free variables. To generalize the implementation so that it also handles terms with free variables requires extra care at the match-case “Lambda y t m”:
  • Substitution would be applicable not only when y x but also when y fv ( n ) to avoid the bound variable y being captured by any free variable present in the substituted term n.
  • If the bound variable y is somehow captured by either of the cases y = x and y fv ( n ) , one possibility to avoid the capture is to introduce a fresh variable and replace it with the bound variable y. Another choice may be to completely discard the naming bound variables by employing de Bruijn indices [26] in the Lambda binder, or alternatively pick a locally nameless strategy [27], or maybe embark on (parametric) higher-order abstract syntax [28]. Opting one of these methods, and adjusting the implementation accordingly is set as a future goal.

3. Type Soundness

We devote this section to step-by-step explore the soundness proof of the type system presented in Figure 4. It may be beneficial to first look into the chart in Figure 6 that exhibits the dependency among statements proven further in this section, and then read the proof terms in detail.
Remark that the definition, lemma, and theorem names in the upcoming text are indeed links to the corresponding formalization in the Coq library. Please click on the names to browse the related code.
Lemma 1 
(istypechecked_app). t 1 t 2 τ , ( t 1 t 2 ) : τ υ , t 1 : υ τ t 2 : υ .
Proof
The statement is just the inversion of the ( a p p t ) rule presented in Figure 4. Notice that we are trying to show υ , t 1 : υ τ t 2 : υ assuming ( t 1 t 2 ) : τ (H). The proof proceeds with nested case distinctions over the statements, i.e., whether the terms t 1 and t 2 are well-typed under the empty context:
1.
t 1 : κ τ for some arbitrary type κ .
(a)
t 2 : ρ for some arbitrary type ρ . In this case, both t 1 and t 2 are individually well-typed under the empty context. By employing this fact, the rule ( a p p t ) and the hypothesis (H), it is easy to deduce that κ = ρ . Under the same set of assumptions, we could show υ , t 1 : υ τ t 2 : υ holds just by plugging in the type ρ (or equivalently κ ) for υ . The hypothesis (H) would not hold otherwise.
(b)
t 2 : ρ . Given that the application ( t 1 t 2 ) is well-typed, under the empty context, the term t 2 must be well-typed as well. This case is a violation thus the goal is closed by contradiction.
2.
t 1 : κ ρ . Similar to the item above, if the application ( t 1 t 2 ) is well-typed, the term t 1 must also be well-typed under the empty context context. This case is a violation, thus, the goal is closed by contradiction as well.
Lemma 2 
(istypechecked_ite). t 1 t 2 t 3 τ , I T E t 1 t 2 t 3 : τ t 1 = B o o l t 2 : τ t 3 : τ .
Proof.
The statement is the inversion of the rule ( i t e t ) stated in Figure 4. We aim to prove t 1 = B o o l t 2 : τ t 3 : τ provided ITE t 1 t 2 t 3 : τ (H). The proof we present here proceeds with nested case distinctions over the statements, whether the terms t 1 , t 2 and t 3 are well-typed under the empty context:
1
t 1 : κ 1 for some arbitrary type κ 1 .
(a)
t 2 : κ 2 for some arbitrary type κ 2 .
i.
t 3 : κ 3 for some arbitrary type κ 3 . In this case, the terms t 1 , t 2 , and t 3 are all individually well-typed under the empty context. With this, the hypothesis (H), and the rule ( i t e t ), we could simply deduce the facts that κ 1 must be B o o l , and both κ 2 and κ 3 must be τ . Any other choice of κ s would contradict the hypothesis (H).
ii.
t 3 : κ 3 . If the term ITE t 1 t 2 t 3 is well-typed, under the empty context, the term t 3 must also be well-typed. This case is a violation, thus, the goal is closed by contradiction.
(b)
t 2 : κ 2 . The goal in this case similarly holds by contradiction.
2.
t 1 : κ 1 . The goal in this case is closed by contradiction in a similar manner with that of the above item.
Lemma 3 
(istypechecked_fix). t τ , F i x t : τ t : τ τ
Proof.
The statement is the inversion of the rule ( f i x t ) stated in Figure 4. The goal here is to show that t : τ τ holds, assuming Fix t : τ (H). The proof proceeds with a case distinction over the statement whether the term t is well-typed under the empty context:
  • t : κ for some arbitrary type κ . Thanks to the hypothesis (H) and the rule ( f i x t ), we could easily reason that κ must be τ τ ; the hypothesis (H) would not hold otherwise.
  • t : κ . If the term Fix t is well-typed, under the empty context, the term t must also be well-typed. This case is a violation, thus, the goal is closed by contradiction.
Lemma 4 
(istypechecked_plus). t 1 t 2 τ , P l u s t 1 t 2 : τ τ = I n t t 1 : I n t t 2 : I n t
Proof.
The statement is indeed the inversion of the rule ( p l u s t ) in Figure 4. We aim to prove τ = I n t t 1 : I n t t 2 : I n t provided that Plus t 1 t 2 : τ (H). The proof we present here proceeds with nested case distinctions over the statements, i.e., whether the terms t 1 and t 2 are well-typed under the empty context:
1.
t 1 : κ 1 for some arbitrary type κ 1 .
(a)
t 2 : κ 2 for some arbitrary type κ 2 . In this case, the terms t 1 and t 2 are individually well-typed under the empty context. With this, the hypothesis (H), and the rule ( p l u s t ), it is easy to deduce the fact that the types τ , κ 1 and κ 2 must be I n t . Any other choice of κ s and τ would be in contradiction with the hypothesis (H).
(b)
t 2 : κ 2 . If the term Plus t 1 t 2 is well-typed, under the empty context, the term t 2 must also be well-typed. This case is a violation, thus, the goal is closed by contradiction.
2.
t 1 : κ 1 . The goal in this case is closed by contradiction in a similar manner with that of the above item.
The progress statement claims that if an arbitrary term t type-checks under the empty context then it either reduces in a single step into some term t or it is already a value. That is, well-typed terms are never stuck (see Definition 6 for a formal explanation of being stuck for a term). The terms that are well-typed and do not reduce at the same time are those marked values (see Definition 3).
Theorem 1 
(Progress). t , t : τ isvalue t = true t , t β t for some type τ.
Proof.
The proof proceeds with structural induction on the term t. The cases with Ident x, λ x : τ . t , NVal n and BVal b are indeed trivial: the first assumes false by Ident x : τ for some type τ , and the rest are already values.
1.
The case with the application ( t 1 t 2 ), for some terms t 1 and t 2 , is more involved. There, we aim to prove that isvalue  ( t 1 t 2 ) = t r u e   t , ( t 1 t 2 ) β t given ( t 1 t 2 ) : τ ( H t c ) for some type τ , along with two induction hypotheses t 1 : τ 1 isvalue  t 1 = t r u e   t 1 , t 1 β t 1 ( I H t 1 ) for some type τ 1 , and  t 2 : τ 2 isvalue  t 2 = t r u e   t 2 , t 2 β t 2 ( I H t 2 ) for some type τ 2 . Notice that isvalue  ( t 1 t 2 ) = f a l s e ; therefore, we consider showing the right disjunction t , ( t 1 t 2 ) β t here. It is easy to demonstrate that the Boolean function isvalue is decidable. That is, t , isvalue t = t r u e isvalue t = f a l s e . We start off with a case analysis, specializing this fact on the term t 1 , and  throw two individual subgoals to close the assuming isvalue t 1 = t r u e and isvalue t 1 = f a l s e , independently:
(a)
isvalue t 1 = t r u e . We proceed with a case analysis specializing the decidability of the isvalue function, this time with the term t 2 and obtain two more subgoals to prove, given isvalue t 2 = t r u e and isvalue t 2 = f a l s e separately:
i.
isvalue t 2 = t r u e . On a case analysis over the term t 1 , we in fact have to prove the below three cases in which t 1 is a value (other cases, such as t 1 being ITE e 1 e 2 e 3 , are trivial just because t 1 s are not values that yield in contradictory cases):
  • t 1 = λ x : τ x . e , for some type τ x . Mind that the goal here turns out to be t , ( λ x : τ x e ) t 2 β t . There obviously exists some t ; that is the substitution e [ x : = t 2 ] , closing the goal thanks to the rule ( a p p 3 ) in Figure 2.
  • t 1 = NVal n . In this case, the hypothesis ( H t c ) takes the following shape: ( NVal n ) t 2 : τ , which is indeed false and yields in a contradiction as the first term in an application needs to be of some arrow-type but it is of type I n t here.
  • t 1 = BVal b . This case is proven in a similar fashion to that of the above item.
ii.
isvalue t 2 = f a l s e . Thanks to Lemma 1, we have t 2 : τ 2 , for some type τ 2 out of ( t 1 t 2 ) : τ . We use this fact to specialize the induction hypothesis ( I H t 2 ) to turn it into isvalue t 2 = t r u e t , t 2 β t . We destruct this, and are supposed to prove the below statements, assuming isvalue t 2 = t r u e and t 2 , t 2 β t 2 individually:
A.
isvalue t 2 = t r u e . This case holds by contradiction.
B.
t 2 , t 2 β t 2 . On a case analysis over the term t 1 , we in fact have to prove the below three cases in which t 1 is a value (other cases, such as t 1 being ITE e 1 e 2 e 3 , are trivial just because t 1 s are not values that yield in contradictory cases):
  • t 1 = λ x : τ x . e , for some type τ x . The goal we aim to show in this case is t , ( λ x : τ x . e ) t 2 β t . Such a t obviously exists as ( λ x : τ x . e ) t 2 due to the rule ( a p p 4 ) in Figure 2.
  • t 1 = NVal n . In this case, the hypothesis ( H t c ) takes the following shape: ( NVal n ) t 2 : τ , which is a contradiction, because in an application, the first term needs to be of some arrow-type, but it is I n t here.
  • t 1 = BVal b . This case is proven in a similar manner to that of the above item.
(b)
isvalue t 1 = f a l s e . Thanks to Lemma 1, we have t 1 : τ 1 , for some type τ 1 out of ( t 1 t 2 ) : τ . We use this fact to specialize the induction hypothesis ( I H t 1 ) to turn it into the shape isvalue t 1 = t r u e t , t 1 β t . We destruct this, and are supposed to prove the below statements, assuming isvalue t 1 = t r u e and t 1 , t 1 β t 1 separately:
i.
isvalue t 1 = t r u e . The statement in this case trivially holds by contradiction.
ii.
t 1 , t 1 β t 1 . In a case analysis over the term t 1 , we in fact have to prove subgoals in which t 1 is not a value (other cases such as t 1 being λ x : τ . e are trivial just because t 1 s are values that yield in proofs by contradiction):
  • Recall that we are trying to show t , ( t 1 t 2 ) β t such that t 1 is not a value. We close all such cases uniformly: there definitely exists a t being ( t 1 t 2 ) given t 1 β t 1 , due to the rule ( a p p 2 ) in Figure 2.
2.
Looking into the case with ITE t 1 t 2 t 3 , we need to show isvalue  ITE t 1 t 2 t 3 = t r u e   t , ITE t 1 t 2 t 3 β t given ITE t 1 t 2 t 3 : τ ( H t c ) for some type τ , along with three induction hypotheses t 1 : τ 1 isvalue t 1 = t r u e   t 1 , t 1 β t 1 ( I H t 1 ) for some type τ 1 , t 2 : τ 2 isvalue t 2 = t r u e   t 2 , t 2 β t 2 ( I H t 2 ) for some type τ 2 , and  t 3 : τ 3 isvalue t 3 = t r u e   t 3 , t 3 β t 3 ( I H t 3 ) for some type τ 3 . Notice that the sole case we are supposed to demonstrate is t , ITE t 1 t 2 t 3 β t as isvalue  ITE t 1 t 2 t 3 = f a l s e . Plugging the hypothesis ( H t c ) into Lemma 2, we deduce the facts that t 1 : B o o l ( H a ), t 2 : τ ( H b ), and  t 3 : τ ( H c ). We then specialize the induction hypothesis ( I H t 1 ) with ( H a ), and obtain isvalue  t 1 = t r u e   t 1 , t 1 β t 1 . Destructing this hypothesis, we are supposed to prove the goal t , ITE t 1 t 2 t 3 β t twice, assuming isvalue  t 1 = t r u e and t 1 , t 1 β t 1 individually:
(a)
isvalue t 1 = t r u e . On a case analysis over the term t 1 , we in fact have to prove the below three cases in which t 1 is a value (other cases such as t 1 being F i x f are trivial just because t 1 s are not values that yield in contradictory cases):
  • t 1 = λ x : τ x . e , for some type τ x . It is possible to show that t , ITE ( λ x : τ x . e )   t 2 t 3 β t holds just by contradiction as the hypothesis ( H a ), namely ( λ x : τ x . e ) : B o o l proves False. The Lambda terms are of the arrow-type.
  • t 1 = NVal n . In this case, it is similarly possible to prove False within the set of hypotheses: considering the hypothesis ( H a ), namely NVal n : B o o l , we deduce False as it in fact is NVal n : I n t .
  • t 1 = BVal b . If the Boolean variable b is true, then the statement t , ITE ( BVal t r u e ) t 2 t 3 β t could easily be proven by plugging the term t 2 in place of t due to the rule ( i t e 1 ). If b is the Boolean false, then t is chosen to be t 3 to close the goal due to the rule ( i t e 2 ) in Figure 2.
(b)
t 1 , t 1 β t 1 . The term t 1 is obviously not a value as it reduces at least one step. Therefore, it cannot be BVal b , NVal n , and λ x : τ x . e . We prove the statement t , ITE t 1 t 2 t 3 β t uniformly for the other choices of t 1 as follows: just plug in the term ITE t 1 t 2 t 3 for the term t within the goal, and obtain ITE t 1 t 2 t 3 β ITE t 1 t 2 t 3 , which trivially holds thanks to the rule ( i t e 3 ) presented in Figure 2.
3.
For the case with Fix f , we need to prove that isvalue  Fix f = t r u e   t , Fix f β t given Fix f : τ ( H t c ) for some type τ , along with the induction hypothesis f : τ isvaluef = true f , f β f ( I H f ). Lemma 3 gives proof of the fact that f : τ f , for some type τ f out of ( H t c ). We specialize in the induction hypothesis ( I H f ) with this fact and handle isvalue  f = t r u e   f , f β f . By destructing this, we are supposed to prove the goal t , Fix f β t (as isvalue  Fix f = f a l s e ) twice for both isvalue  f = t r u e and f , f β f .
(a)
isvalue f = t r u e . On a case analysis over the term f, we in fact have to prove the below three cases in which f is a value (other cases, such as f being Plus t 1 t 2 are trivial just because fs are not values that yield in contradictory cases):
  • f = λ x : τ x . e , for some type τ x . It suffices to plug the term e [ x : = Fix ( λ x : τ x . e ) ] into the formula t , Fix ( λ x : τ x . e ) β t , and then apply the rule ( f i x 1 ) in Figure 2 to have this case proven.
  • f = NVal n . In this case, it is possible to prove False within the current context: considering ( H a ), namely Fix ( NVal n ) : τ is simply false as it is an ill-typed term according to the rules in Figure 4. See the rule ( f i x t ) that states that terms of the form Fix f are well-typed only when f is of some arrow-type with the same domain and co-domain. This does not match with the fact that NVal n : I n t .
  • f = BVal b . This case holds due to the same reason as that of t 1 = NVal n given above.
(b)
f , f β f . Given the rule ( f i x 2 ) in Figure 2, one can reason that t , Fix f β t holds simply by plugging the term Fix f in, for  t except for the cases where f is a value. These cases are contradictory as there is no f into which f evaluates.
4.
Considering the case involving Plus t 1 t 2 , we need to show isvalue  Plus t 1 t 2 = t r u e   t , Plus t 1 t 2 β t given Plus t 1 t 2 : τ ( H t c ) for some type τ , along with two induction hypotheses t 1 : τ 1 isvalue t 1 = t r u e   t 1 , t 1 β t 1 ( I H t 1 ) for some type τ 1 , and  t 2 : τ 2 isvalue t 2 = t r u e   t 2 , t 2 β t 2 ( I H t 2 ) for some type τ 2 . Notice that we are supposed to prove only t , Plus t 1 t 2 β t as isvalue  Plus t 1 t 2 = f a l s e . Employing Lemma 4, we deduce the facts that t 1 : I n t ( H a ), and that t 2 : I n t ( H b ) out of the hypothesis ( H t c ). Specializing the induction hypotheses ( I H t 1 ) with ( H a ) and ( I H t 2 ) with ( H b ), we obtain isvalue  t 1 = t r u e   t 1 , t 1 β t 1 and isvalue  t 2 = t r u e   t 2 , t 2 β t 2 . We carry on with a case analysis on the decidability of the isvalue function parameterized by the term t 1 . We, therefore, need to prove the aforementioned goal twice for two distinct cases with isvalue t 1 = t r u e and isvalue t 1 = f a l s e :
(a)
isvalue t 1 = t r u e . Applying a case analysis on the term t 1 , we are supposed to prove the below three cases (others, such as t 1 being Fix f , are trivial just because t 1 s are not values that yield in contradictions):
i.
t 1 = λ x : τ x . e , for some type τ x . Notice that in this case, the goal turns out to be t , Plus ( λ x : τ x . e ) t 2 β t . This holds by contradiction just because the type of λ x : τ x . e is an arrow-type while it is expected to be I n t by the hypothesis ( H a ). Please check out the rule ( l a m t ) given in Figure 4 for a justification.
ii.
t 1 = NVal n . In this case, we start off destructing the induction hypothesis ( I H t 2 ), and are in the need of proving the goal t , Plus NVal n t 2   β t twice provided isvalue t 2 = t r u e and t 2 , t 2 β t 2 individually:
A.
isvalue t 2 = t r u e . We proceed with the case analysis of the term t 2 , we are supposed to prove the below three cases (others, such as t 2 being Fix f , are trivial just because t 2 s are not values that yield in contradictions):
  • t 2 = λ x : τ x . e , for some type τ x . Here, we need to show that t , Plus ( NVal n ) ( λ x : τ x . e ) β t holds. This is doable again by contradiction as the term λ x : τ x . e is of an arrow-type, while it is expected to be I n t by the hypothesis ( H b ).
  • t 2 = NVal m . In this case, we could simply show that t , Plus ( NVal n ) ( NVal m ) β t holds by first plugging in the term NVal ( n + m ) for t , and then employing the rule ( p l u s 1 ) presented in Figure 2.
  • t 2 = BVal b . The goal t , Plus ( NVal n ) ( BVal b ) β t in this case holds also by contradiction: the type of ( BVal b ) is B o o l while it is expected to be I n t by the rule ( H b ).
B.
t 2 , t 2 β t 2 . In this case, t , Plus ( NVal n ) t 2 β t needs to be shown. In cases where t 2 is a value, we close the goal by contradiction, as t 2 , t 2 β t 2 allows for proving False: values do not evaluate any further. For the rest, we plug the term Plus ( NVal n ) t 2 into the goal, for the term t , and solve it with the rule ( p l u s 2 ) stated in Figure 2.
iii.
t 1 = BVal b . It is possible to show that t , Plus ( BVal b ) t 2 β t by contradiction as the type of ( BVal b ) is B o o l while it is here expected to be I n t by the rule ( H a ).
(b)
isvalue t 1 = f a l s e . On a case analysis over the term t 1 , we in fact have to prove subgoals where t 1 is not a value (other cases such as t 1 being λ x : τ . e are trivial just because t 1 s are values that yield in contradictory cases):
  • Recall that we are trying to show t , Plus t 1 t 2 β t , such that t 1 is not a value. We close all such cases uniformly: there definitely exists a t as Plus t 1 t 2 given t 1 β t 1 , thanks to the rule ( p l u s 3 ) presented in Figure 2.
5.
The remaining cases with, for instance, Minus t 1 t 2 , could be proven by employing a very similar idea presented in the above item 4.
We summarize below the given Coq implementation, proof of Theorem 1, in such a way that we highlight the crucial points itemized in the above pen-and-paper proof by comment-outs. Please refer to the accompanying library for the complete proof.
Axioms 12 00043 i007Axioms 12 00043 i008
Lemma 5
(subst_preserves_typing). x t v τ υ Γ , Γ , x : υ t : τ v : υ Γ t [ x : = v ] : τ .
Proof.
The statement informally says that under some context Γ , substitution of the string x with some term v within the term t, the type of t remains unchanged, provided Γ , x : υ t : τ ( H a ) and v : υ ( H b ). We argue by structural induction on the term t:
  • t = Ident s for some arbitrary string s. If x = s , the hypothesis H a takes the following shape: Γ , s : υ Ident s : τ which implies that υ = τ . The goal Γ ( Ident s ) [ s : = v ] : υ simplifies into Γ v : υ by Definition 2 of the substitution function. Employing the fact that Γ Λ e κ , Γ e : κ   ( y , y fv y Γ ( y ) = Λ ( y ) )   Λ e : κ (named context_invariance in the Coq code), we deduce Γ v : υ out of the hypothesis H b , and the goal is closed. Else if x s then ( H a ) turns into Γ ( s ) = τ . The goal Γ ( Ident s ) [ x : = v ] : τ simplifies into Γ ( s ) = τ again by Definition 2. This is in fact the hypothesis ( H b ) itself.
  • t = λ s : κ . e for some arbitrary string s, type κ , and term e. The goal we aim to prove is Γ ( λ s : κ . e ) [ x : = v ] : τ , provided an induction hypothesis x v τ υ Γ , Γ , x : υ e : τ v : υ Γ e [ x : = v ] : τ ( I H e ). If x = s then we have ( λ s : κ . e ) [ s : = v ] amounts to λ s : κ . e by Definition 2. Therefore, the goal turns out to be Γ λ s : κ . e : τ . Using the fact that Γ Λ e κ , Γ e : κ ( y , y fv y   Γ ( y ) = Λ ( y ) )   Λ e : κ (context_invariance in the Coq code) over the contexts Γ , s : υ and Γ with the hypothesis H a (namely, Γ , s : υ λ s : κ . e : τ ), we manage to extend the list of assumptions with Γ λ s : κ . e : τ , and have the goal closed. If x s , we need to show that Γ λ s : κ . e [ x : = v ] : τ or better that Γ , s : κ e [ x : = v ] : τ thanks to Definition 2 and to the ( a p p t ) rule in Figure 4. Remark that in this case, the hypothesis ( H a ) first takes the shape Γ , x : υ λ s : κ . e : τ then simplifies into Γ , x : υ , s : κ e : τ again by the ( a p p t ) rule. Specializing the induction hypothesis ( I H e ) with the context Γ , s : κ , simplified version of ( H a ) and ( H b ), we close this goal.
  • t = ( t 1 t 2 ) for some terms t 1 and t 2 . We try proving Γ ( t 1 t 2 ) [ x : = v ] : τ given x v τ υ Γ , Γ , x : υ t 1 : τ v : υ Γ t 1 [ x : = v ] : τ ( I H t 1 ) and x v τ υ Γ , Γ , x : υ t 2 : τ v : υ Γ t 2 [ x : = v ] : τ ( I H t 2 ) as induction hypotheses. We deduce Γ , x : υ t 1 : κ τ (H) and Γ , x : υ t 2 : κ ( H 0 ), for some type κ , by inversion over the hypothesis ( H a ), namely Γ , x : υ ( t 1 t 2 ) : τ . Using (H) and ( H b ) in ( I H t 1 ), and ( H 0 ) and ( H b ) in ( I H t 2 ), we, respectively, obtain Γ t 1 [ x : = v ] : κ τ and Γ t 2 [ x : = v ] : κ , which prove the goal thanks to Definition 4 of the substitution function and the rule ( a p p t ) in Figure 4.
  • t = ITE t 1 t 2 t 3 for some terms t 1 , t 2 , and t 3 . The statement we intend to show in this case turns out to be Γ ( ITE t 1 t 2 t 3 ) [ x : = v ] : τ given x v τ υ Γ , Γ , x : υ t 1 : τ v : υ Γ t 1 [ x : = v ] : τ ( I H t 1 ), x v τ υ Γ , Γ , x : υ t 2 : τ v : υ Γ t 2 [ x : = v ] : τ ( I H t 2 ) and x v τ υ Γ , Γ , x : υ t 3 : τ v : υ Γ t 3 [ x : = v ] : τ ( I H t 3 ) as induction hypotheses. It is quite easy to infer Γ , x : υ t 1 : B o o l (H), Γ , x : υ t 2 : τ ( H 0 ), and Γ , x : υ t 3 : τ ( H 1 ) by inversion over the hypothesis ( H a ), namely Γ , x : υ ITE t 1 t 2 t 3 : τ . We then specialize ( I H t 1 ) with (H) and ( H b ), ( I H t 2 ) with ( H 0 ) and ( H b ), and ( I H t 3 ) with ( H 1 ) and ( H b ) to respectively obtain Γ t 1 [ x : = v ] : B o o l , Γ t 2 [ x : = v ] : τ and Γ t 3 [ x : = v ] : τ . These are adequate to prove the statement due to Definition 4 of the substitution function and the rule ( i t e t ) in Figure 4.
  • t = Fix t 1 for some term t 1 . The goal of the case is of the following shape: Γ ( Fix t 1 ) [ x : = v ] : τ . We additionally have a single induction hypothesis x v τ υ Γ , Γ , x : υ t 1 : τ v : υ Γ t 1 [ x : = v ] : τ ( I H t 1 ). The hypothesis ( H a ), Γ , x : υ Fix t 1 : τ , entails by inversion that Γ , x : υ t 1 : τ τ (H). We then specialize ( I H t 1 ) with (H) and ( H b ) to have Γ t 1 [ x : = v ] : τ τ . This is enough to close the goal thanks to Definition 4 of the substitution function and the rule ( f i x t ) in Figure 4.
  • t = Plus t 1 t 2 for some terms t 1 and t 2 . The goal we aim to close in this case is Γ ( Plus t 1 t 2 ) [ x : = v ] : τ along with two induction hypotheses x v τ υ Γ , Γ , x : υ t 1 : τ v : υ Γ t 1 [ x : = v ] : τ ( I H t 1 ), x v τ υ Γ , Γ , x : υ t 2 : τ v : υ Γ t 2 [ x : = v ] : τ ( I H t 2 ). We infer Γ , x : υ t 1 : I n t (H) and Γ , x : υ t 2 : I n t ( H 0 ) inverting the hypothesis ( H a ). Lastly, we specialize ( I H t 1 ) with (H) and ( H b ), ( I H t 2 ) with ( H 0 ) and ( H b ) to handle Γ t 1 [ x : = v ] : I n t , Γ t 2 [ x : = v ] : I n t which prove the goal due to Definition 4 and the rule ( p l u s t ) in Figure 4.
  • The cases with t, being either Minus t 1 t 2 , Mult t 1 t 2 , Eq t 1 t 2 , or Gt t 1 t 2 follow the same lines with the proof given in the above item 6. The cases where t = NVal n and t = BVal b are trivial just because the substitution function has no impact on these terms.
The preservation statement claims that the type of a given term does not vary under beta-reduction.
Theorem 2
(Preservation). t t , t : τ t β t t : τ .
Proof.
The proof proceeds by a structural induction over the term t. The cases involving Ident x , λ x : τ . e , NVal n , and BVal b trivially hold by contradiction: these terms do not reduce any further, contradicting the assumption t β t .
1.
The case with the application ( t 1 t 2 ), for some arbitrary terms t 1 and t 2 , are more appealing and, thus, deserve a closer look. Here, we are supposed to show (for all types τ ) that t : τ holds; provided ( t 1 t 2 ) : τ (H), ( t 1 t 2 ) β t ( H 0 ), and a pair of induction hypotheses t τ , t 1 : τ t 1 β t t : τ ( I H t 1 ) and t τ , t 2 : τ t 2 β t t : τ ( I H t 2 ). Notice that by plugging in the hypothesis (H) into Lemma 1, we can deduce the facts that t 1 : υ τ ( H 1 ) and t 2 : υ ( H 2 ), for some type υ . At this stage, we apply a case analysis on the term t 1 (below the goals) to close:
(a)
t 1 = λ x : υ . e for some term e and type υ . We definitely obtain some t after beta-reducing the term inhabited by the hypothesis (H) ( λ x : υ . e ) t 2 depending on the choice of whether t 2 is a value or not:
i.
isvalue t 2 = t r u e . In this case, t amounts to e [ x : = t 2 ] , due to the rule ( a p p 3 ) presented in Figure 2, and we are expected to prove that e [ x : = t 2 ] : τ . Thanks to Lemma 5, to obtain e [ x : = t 2 ] : τ (proven), we need to close two goals, which are x : υ e : τ and t 2 : υ :
  • x : υ e : τ . Recall that we have λ x : υ . e : υ τ due to ( H 1 ). We solve the goal just by inverting the rule ( l a m t ) in Figure 4.
  • t 2 : υ . This one is exactly ( H 2 ).
ii.
isvalue t 2 = f a l s e . Thanks to Progress Theorem 1 and the hypothesis ( H 1 ), we have isvalue t 2 = t r u e t 2 , t 2 β t 2 . As the left side of the disjunction is contradictory to the assumption of the case, we focus on the right side, which tells us that there exists some t 2 , such that t 2 β t 2 . Therefore, t amounts to ( λ x : υ . e ) t 2 due to the rule ( a p p 4 ) presented in Figure 2. Namely, we are supposed to show that ( λ x : υ . e ) t 2 : τ holds. By properly specializing the induction hypothesis ( I H t 2 ), we end up with t 2 : υ . With this information in hand, just by employing the rule ( a p p t ) in Figure 4, we ensure that the application ( λ x : υ . e ) t 2 is of type τ under the empty context.
(b)
t 1 = ( e 1 e 2 ) for some arbitrary terms e 1 and e 2 . It is known by ( H 1 ) that the application ( e 1 e 2 ) is of type υ τ under the empty context. Passing this well-typed information to Progress Theorem 1, we have isvalue ( e 1 e 2 ) = t r u e t 1 , ( e 1 e 2 ) β t 1 . Due to the fact that isvalue ( e 1 e 2 ) = f a l s e , we are left with t 1 , ( e 1 e 2 ) β t 1 . Therefore, the goal that we aim to prove in this case takes the following shape: t 1 t 2 : τ due to the rule ( a p p 2 ) presented in Figure 2. Specializing the induction hypothesis ( I H t 1 ) with the correct ingredients gives us t 1 : υ τ . Making use of the hypothesis ( H 2 ) and the rule ( a p p t ) placed in Figure 4, we conclude that t 1 t 2 : τ holds.
(c)
t 1 = ITE e 1 e 2 e 3 for some arbitrary terms e 1 , e 2 and e 3 . Similar to the proof in the above item, we know that the term ITE e 1 e 2 e 3 is of type υ τ under the empty context. This, Progress Theorem 1 gives us isvalue ITE e 1 e 2 e 3 = t r u e t 1 , ITE e 1 e 2 e 3 β t 1 . Just that isvalue ITE e 1 e 2 e 3 = t r u e is incorrect, we focus on t 1 , ( ITE e 1 e 2 e 3 )   β t 1 . This heads us toward proving t 1 t 2 : τ due to the rule ( a p p 2 ) presented in Figure 2. Similar to that of the above item (b), we specialize in the induction hypothesis ( I H t 1 ) with the correct ingredients, and have t 1 : υ τ . We close this goal just by employing the hypothesis ( H 2 ) and the rule ( a p p t ) appearing in Figure 4.
(d)
t 1 = Fix e 1 for some arbitrary term e 1 . By chasing the exact same steps demonstrated in the above items (b) and (c), we end up retaining t 1 , Fix e 1 β t 1 to show t 1 t 2 : τ , which we solve again by putting the induction hypothesis ( I H t 2 ) together with the rule ( a p p t ) in operation.
(e)
t 1 = ( Plus e 1 e 2 ) for some arbitrary terms e 1 and e 2 . The goal in this case is proven by contradiction as due to the hypothesis ( H 1 ), the term t 1 needs to be of some arrow-type υ τ , but it is of type I n t .
(f)
The other cases in which the term t 1 appears to be either NVal n , Minus e 1 e 2 , Mult e 1 e 2 , Eq e 1 e 2 , or Gt e 1 e 2 , and could be proven in a similar manner with that of the above item (e). The goal where t 1 amounts to BVal b is similarly proven with a single difference, where t 1 is of type B o o l , not I n t . Lastly, the goal with t 1 = Ident x holds by contradiction as the term t 1 is ill-typed under the empty context.
2.
t = ITE t 1 t 2 t 3 for some terms t 1 , t 2 and t 3 . In this case, we aim to prove for all types τ that t : τ holds; given that ITE t 1 t 2 t 3 : τ (H), ITE t 1 t 2 t 3 β t ( H 0 ) along with three induction hypotheses t τ , t 1 : τ t 1 β t t : τ ( I H t 1 ), t τ , t 2 : τ t 2 β t t : τ ( I H t 2 ), and t τ , t 3 : τ t 3 β t t : τ ( I H t 3 ). Note also that we deduce the facts t 1 : B o o l ( H a ), t 2 : τ ( H b ), and  t 3 : τ ( H c ) by specializing Lemma 2 with the hypothesis (H). The proof proceeds with a case analysis over the term t 1 , and  requires the following cases to be proven:
(a)
The goals in which the term t 1 is Ident x , NVal n , λ x : υ . e , Plus e 1 e 2 , Minus e 1 e 2 , Mult e 1 e 2 , Eq e 1 e 2 , or Gt e 1 e 2 are trivially shown by contradictions, as none of these terms are of type B o o l as expected by the hypothesis ( H a ).
(b)
t 1 = ( e 1 e 2 ) for some arbitrary terms e 1 and e 2 . The hypothesis H a tells us that ( e 1 e 2 ) : B o o l . This, with Progress Theorem 1, entails that isvalue ( e 1 e 2 ) = t r u e t 1 , ( e 1 e 2 ) β t 1 . The left side of the disjunction is obviously incorrect. We, therefore, obtain t 1 , ( e 1 e 2 ) β t 1 . Accordingly, the goal we intend to prove in this case turns out to be ITE t 1 t 2 t 3 : τ due to the rule ( i t e 3 ) presented in Figure 2. By specializing the induction hypothesis ( I H t 1 ) with proper terms and types, we have t 1 : B o o l . Thanks to the hypotheses ( H b ), ( H c ), and the rule ( i t e t ) given in Figure 4, we show that ( ITE t 1 t 2 t 3 ) : τ .
(c)
t 1 = BVal b for Boolean b. We carry on with a case distinction on b:
  • if b is Boolean true: ITE ( BVal true ) t 2 t 3 β t 2 , thanks to the rule ( i t e 1 ) presented in Figure 2. Therefore, the goal takes the shape t 2 : τ , which is the hypothesis ( H b ).
  • if b is Boolean false: similarly, ITE ( BVal false ) t 2 t 3 β t 3 , thanks to the rule ( i t e 2 ) stated in Figure 2. The goal is now t 3 : τ . This is trivial as it is exactly the hypothesis ( H c ).
(d)
t 1 = ITE e 1 e 2 e 3 for some arbitrary terms e 1 , e 2 and e 3 . The hypothesis ( H a ) entails that ITE e 1 e 2 e 3 : B o o l . Progress Theorem 1 over this fact gives isvalue ITE e 1 e 2 e 3 = t r u e t 1 , ITE e 1 e 2 e 3 β t 1 . Provided that isvalue ITE e 1 e 2 e 3 = f a l s e , we focus on the right side of the disjunction; that is t 1 , ITE e 1 e 2 e 3 β t 1 . In this parallel, the goal we want to close is ITE t 1 t 2 t 3 : τ thanks to the rule ( i t e 3 ) presented in Figure 2. By specializing the induction hypothesis ( I H t 1 ) with proper terms and types, we have t 1 : B o o l . Thanks to the hypotheses ( H b ), ( H c ), and the rule ( i t e t ) stated in Figure 4, we show that ITE t 1 t 2 t 3 : τ .
(e)
t 1 = Fix f for some term f. Similar to case (d) above, the hypothesis ( H a ) entails that Fix f : τ . This, with Progress Theorem 1, we deduce isvalue Fix f = t r u e f , Fix f β f . As it is obvious that isvalue Fix f = f a l s e , we are left with f , Fix f β f . The goal we want to close here is that ITE f t 2 t 3 : τ due to the rule ( i t e 3 ) presented in Figure 2. We now specialize the induction hypothesis ( I H t 1 ) with proper terms and types, and obtain f : B o o l . Thanks to the hypotheses ( H b ), ( H c ), and the rule ( i t e t ) appearing in Figure 4, we prove that ITE f t 2 t 3 : τ .
3.
For the case Fix f , we aim to prove for all types τ that f : τ holds; given that Fix f : τ (H), Fix f β t ( H 0 ) strengthened with the induction hypothesis f τ , f : τ f β f f : τ ( I H f ). Moreover, we have f : τ τ ( H a ) when Lemma 3 is applied to the hypothesis (H). The proof proceeds with a case analysis over the term f, and requires the following cases to be proven:
(a)
The goals in which the term t 1 is any of Ident x , NVal n , BVal b , Plus e 1 e 2 , Minus e 1 e 2 , Mult e 1 e 2 , Eq e 1 e 2 and Gt e 1 e 2 are trivially demonstrated by contradiction as none of these terms are of the arrow type τ τ as expected by the hypothesis ( H a ).
(b)
f = λ x : υ . e for some term e and type υ . Recall that the rule ( f i x 1 ) stated in Figure 2, we have Fix ( λ x : υ . e ) β e [ x : = Fix ( λ x : υ . e ) ] . Notice that, on a side note, the term λ x : υ . e needs to be of type τ τ due to the hypothesis ( H a ). By inversion here, we deduce that υ = τ and x : τ e : τ ( H b ). Having said that, let us look into the statement that needs to be proven in this case: e [ x : = Fix ( λ x : τ . e ) ] : τ (due to the rule ( f i x 1 ) presented in Figure 2). Thanks to Lemma 5, to prove the mentioned goal, we need to close two goals: x : τ e : τ and Fix ( λ x : τ . e ) : τ .
  • x : τ e : τ . This is exactly the hypothesis ( H b ).
  • Fix ( λ x : τ . e ) : τ . This one matches with the hypothesis (H).
(c)
f = ( e 1 e 2 ) for some arbitrary terms e 1 and e 2 . The hypothesis ( H a ) entails that ( e 1 e 2 ) : τ τ . Employing this fact within Progress Theorem 1, we deduce isvalue ( e 1 e 2 ) = t r u e f , ( e 1 e 2 ) β f . The left side of the disjunction is obviously incorrect. We therefore obtain f , ( e 1 e 2 ) β f . Thus the goal turns out to be Fix f : τ due to the rule ( f i x 2 ) presented in Figure 2. By properly specializing the induction hypothesis ( I H f ), we have f : τ τ . Now by the rule ( f i x t ) given in Figure 4, we conclude that Fix f : τ .
(d)
f = ITE e 1 e 2 e 3 for some arbitrary terms e 1 , e 2 and e 3 . Similar to case (c) above, the hypothesis ( H a ) entails that ITE e 1 e 2 e 3 : τ τ . Progress Theorem 1 specialized with this fact implies that isvalue ITE e 1 e 2 e 3 = t r u e t 1 , ITE e 1 e 2 e 3 β t 1 . Provided that isvalue ITE e 1 e 2 e 3 = f a l s e , we focus on the right side of the disjunction; that is f , ITE e 1 e 2 e 3 β f . In this parallel, the goal we want to close here is Fix f : τ due to the rule ( f i x 2 ) presented in Figure 2. We now specialize the induction hypothesis ( I H f ), and obtain f : τ τ . Now by the rule ( f i x t ) stated in Figure 4, we conclude that Fix f : τ .
(e)
f = Fix e for some arbitrary term e. By following the exact same steps presented in the above items (c) and (d), we end up having f , Fix e β f to show Fix f : τ (due to the rule ( f i x 2 ) presented in Figure 2) which we solve again by putting the induction hypothesis ( I H f ) together with the rule ( f i x t ) in use.
4.
Concerning the case with t = Plus t 1 t 2 , for some arbitrarily chosen terms, t 1 and t 2 , we want to prove for all types τ that t : τ holds, provided that Plus t 1 t 2 : τ (H), Plus t 1 t 2 β t ( H 0 ) and two induction hypotheses t τ , t 1 : τ t 1 β t t : τ ( I H t 1 ), t τ , t 2 : τ t 2 β t t : τ ( I H t 2 ). In addition to these, we enrich the set of hypotheses with τ = I n t ( H a ), t 1 : I n t ( H b ), and t 2 : I n t ( H c ) just by applying Lemma 4 over the hypothesis (H). The proof proceeds with a case distinction over the term t 1 , and throws us cases to prove:
(a)
The goals in which term t 1 is Ident x , BVal b , ( λ x : υ . e ) , ( Eq e 1 e 2 ) , or ( Gt e 1 e 2 ) and trivially proven by contradiction as none of these terms are of type I n t as expected by the hypothesis ( H b ).
(b)
t 1 = ( e 1 e 2 ) for some arbitrary terms e 1 and e 2 . We deduce out of the hypothesis ( H b ) that ( e 1 e 2 ) : I n t . With this information, we could further infer that isvalue ( e 1 e 2 ) = t r u e t 1 , ( e 1 e 2 ) β t 1 thanks to Progress Theorem 1. Given that isvalue ( e 1 e 2 ) = f a l s e , we take t 1 , ( e 1 e 2 ) β t 1 into account, and therefore the goal takes the following shape: Plus t 1 t 2 : I n t , due to the rule ( p l u s 3 ) presented in Figure 2. We could put the induction hypothesis ( I H t 1 ) into the following shape: t 1 : I n t employing the hypothesis ( H b ). Now, by using the rule ( p l u s t ), and the hypothesis ( H c ), we conclude that Plus t 1 t 2 : I n t holds.
(c)
t 1 = NVal n for some Coq natural n. Thanks to the hypothesis ( H c ), we already know that t 2 : I n t . Applying Progress Theorem 1 to this fact, we obtain isvalue t 2 = t r u e t 2 , t 2 β t 2 . Destructing this disjunction throws us the following two goals to prove, independently assuming isvalue t 2 = t r u e and t 2 , t 2 β t 2 :
  • isvalue t 2 = t r u e . The only choice that makes this case non-contradictory is that of t 2 = NVal m for a Coq natural m. Other cases lead to contradictions disobeying either isvalue t 2 = t r u e or t 2 : I n t . Using the rule ( p l u s 1 ) shown in Figure 2, we have Plus ( NVal n ) ( NVal m ) β NVal ( n + m ) . Therefore, the statement we try proving here is NVal ( n + m ) : I n t , which is entailed by the rule ( n v a l t ) presented in Figure 4.
  • t 2 , t 2 β t 2 . We proceed with a case distinction on the term t 2 . Note that the statements where t 2 is a value trivially hold, no further reductions from t 2 are possible, which contradicts the assumption of the case. We have the statement Plus ( NVal n ) t 2 : I n t to be proven for the remaining cases, due to the rule ( p l u s 2 ) stated in Figure 2. To prove this statement, we specialize the induction hypothesis ( I H t 2 ) with proper terms and types, and turn it into t 2 : I n t . This fact and the rule ( p l u s t ) presented in Figure 4 give us Plus ( NVal n ) t 2 : I n t .
(d)
t 1 = ITE e 1 e 2 e 3 for some arbitrary terms e 1 , e 2 and e 3 . The hypothesis ( H b ) can be used to infer ITE e 1 e 2 e 3 : I n t . Using this within Progress Theorem 1, it is possible to infer isvalue ITE e 1 e 2 e 3 = t r u e   t 1 , ITE e 1 e 2 e 3 β t 1 . Recall that only the right side of this disjunction is useful as the other leads to a contradiction. Building on this, our goal here turns out to be Plus t 1 t 2 : I n t due to the rule ( p l u s 3 ) given in Figure 2. We then specialize the induction hypothesis ( I H t 1 ) properly and obtain t 1 : I n t . By the rule ( p l u s t ) and the hypothesis ( H c ), we have Plus t 1 t 2 : I n t proven.
(e)
t 1 = Fix f for some arbitrary term f. We follow the exact same steps presented in the above items (b) and (d): first infer t 1 , Fix f β t 1 then show Plus t 1 t 2 : I n t by employing the rule ( p l u s t ), and putting the induction hypothesis ( I H t 1 ) in the intended shape.
(f)
t 1 = Plus e 1 e 2 for some arbitrary terms e 1 and e 2 . We follow the same step with that of the above item (e). That is, we first have t 1 , Plus e 1 e 2 β t 1 out of Progress Theorem 1, and aim at proving Plus t 1 t 2 : I n t (thanks to the rule ( p l u s 3 ) presented in Figure 2). The proof is constructed out of the rule ( p l u s t ) and correctly shaped induction hypothesis ( I H t 1 ).
(g)
The other cases in which the term t 1 appears to be Minus e 1 e 2 or Mult e 1 e 2 could be proven in a similar manner to Plus e 1 e 2 described in the above item (f).
5.
The remaining cases with, for instance, Mult t 1 t 2 , could be proven, employing a very similar idea presented in the above item 4.
We summarize below, in a Coq implementation, a proof of Theorem 2 marking the items presented in the above pen-and-paper proof with comment-outs. Please refer to the accompanying library for the complete proof.
Axioms 12 00043 i009Axioms 12 00043 i010
Definition 5
(Multi-Step Evaluation). We define the multi-step evaluation function (evaln) as the reflexive-transitive closure of the beta-reduction upper-bounded by a natural n:
evaln t 0t
evaln t (S n)let t β t i n evaln t n
In Coq, we wrap the output term of the evaln function with Coq’s option type. By this, we aim to handle the cases in which t has no further evaluation steps with None:Axioms 12 00043 i011
Definition 6
(Stuck). A term t is said to be stuck if there exists no t , such that t β t and t is not a value. That formally is
t , t , t β t i s v a l u e t = f a l s e .
It is straightforward to reflect this definition into Coq: Axioms 12 00043 i012
The soundness statement just combines the claims of that of progress and preservation. Namely, for every well-typed term t, if after n reduction steps, t reduces into some term t then t cannot be stuck.
Theorem 3
(Type Soundness). n t t τ , t : τ e v a l n t n = t ¬ s t u c k t .
Proof.
Unfolding the definitions stuck and not, we are supposed to prove False (in Coq’s Prop) provided that t : τ ( H a ), e v a l n t n = t ( H b ), t , t β t ( H n e ) and isvalue t = f a l s e ( H n v ). The proof proceeds by a structural induction over the natural number n throwing us two cases to prove.
  • n = 0 . Notice that the hypothesis ( H b ) (with n = 0 ) entails that t = t . We employ Progress Theorem 1 specialized by the hypothesis ( H a ), and deduce isvalue t = t r u e   t , t β t . The goal, in this case, is trivially proven as the left side of the disjunction contradicts with ( H n v ), while the right-hand side contradicts with ( H n e ).
  • n = S m . In this case, we additionally have the induction hypothesis t t τ , t : τ e v a l n t m = t t , t β t isvalue t = f a l s e False ( I H n ). We again make use of Progress Theorem 1 specialized by the hypothesis ( H a ), and obtain isvalue t = t r u e   e , t β e . We now destruct this fact, and are supposed to prove the goal, which is False here, twice assuming isvalue t = t r u e and e , t β e independently:
    • isvalue t = t r u e . It is obvious in this case that the term t does not reduce even a single step further. Namely, there is no t , such that e v a l n t ( S m ) = t , which contradicts the hypothesis ( H b ), and closes the goal.
    • e , t β e . We know that there is some term e into which the term t reduces in a single beta-step. We also know by the hypothesis ( H b ) that t reduces into some term t in S m (or m + 1 ) steps. Putting these together, we infer that the term e reduces into the t in m steps, namely e v a l n e m = t . Moreover, we specialize the Preservation Theorem 2 with the hypothesis ( H a ) and the fact that t β e to retain e : τ ( H t e ). This time, making use of ( H t e ) and the fact that e v a l n e m = t , we put the induction hypothesis ( I H n ) into the following shape: t , t β t isvalue t = f a l s e False . Into this, we plug the conjunction of the hypotheses ( H n e ) and ( H n v ), and obtain a proof of False, which literally implies everything.
In a Coq implementation, the proof above could be summarized as follows:
Axioms 12 00043 i013

4. Discussion

Observe that the detailed interpreter was developed in an extensible fashion. Namely, it is possible to extend the language of types, such that the object language becomes polymorphically typed. One can similarly extend the language of terms with other programming constructs, such as pairs, lists, match constructs, etc., to handle a richer object language safely interpreted. The formalization already contains an extension of λ interpreted as an application. For a use case that deals with a more involved and richer language, we kindly ask the reader to refer to a definitional interpreter (Section 1.1) for a polymorphically typed functional language written in Haskell. The same approach could easily be followed in the current Coq formalization (with additional cases brought over to prove) and reserved to be targeted as future work.
Obviously, for an object language that supports dependent types, the presented approach would not work well. That is because in a dependently typed setting, type-checking requires an evaluation; thus, it is better to have a single language for terms and types.
Remark also that interpreting object languages with computational side effects is beyond the scope of the implementation presented here. It is possible to extend the interpreter’s formalization in Coq with certain monads, as in [29], and handle related impurities. Moreover, monads could benefit from generating fresh variables to avoid ’variable capture’ that potentially comes up in substituting Lambda terms.

5. Conclusions

We developed (in the proof assistant Coq) a definitional interpreter and a type-checker for a purely functional language based on (some extension of) the simply typed Lambda calculus. We formally prove that the type-checker is sound with respect to the evaluation strategy. Namely, every term that type-checks also evaluates (or reduces) unless it is a value. We formalized the soundness proof by employing progress and presentation properties, and discuss the related lemmata in technical detail in the pen-and-paper style containing pointers to the corresponding Coq code. Moreover, there are a few items that could extend the development and be set as future goals. We list them below.
  • The formalization does not handle de Bruijn indices [26] or other methods [27,28] that help avoid the variable capture, concerning terms involving free variables. The technical machinery related to these methods will be implemented.
  • Extending the interpreter to handle polymorphically typed Lambda calculus embarking on the same approach presented herenote1 is (a definitional interpreted for a polymorphically typed functional language coded in Haskell) another goal to achieve.
  • The interpreter could be expanded and scaled to handle some other programming blocks, such as pairs, match-end constructs, let bindings, pairs, lists, and records.
The accompanying Coq sources were tested to compile with coqc version coq-8.15.2 within approximately 43 s on an Intel Core i7-7600U machine running Ubuntu 22.04 LTS over 16 GB of external memory.

Funding

This research received no external funding.

Data Availability Statement

The data presented in this study are openly available at https://github.com/ekiciburak/extSTLC (accessed on 4 September 2022).

Conflicts of Interest

The author declares no conflict of interest.

Appendix A. Organization of the Coq Sources

To declare terms and types, we employ Coq inductive predicates. As mentioned earlier, type-checking and beta-reduction were implemented, embarking on the definitional approach. The return types of both definitions are wrapped by Coq’s option type to handle ill-typed terms and those do not reduce any further. Some relevant Coq files from the library are itemized below, such that the subsequent file depends on the previously stated ones. For instance, Soundness.v depends on all files.
  • Auxiliaries.v: includes some simple proofs of statements about contexts that are indeed defined as lists of pairs.
  • Terms.v: involves declarations of terms and types along with decidable equality among terms and types, and reflection proofs of such equalities into Coq’s Prop.
  • Typecheck.v: the file in which the function typecheck is implemented. It also contains proofs of some properties given in Lemmata 1–5. To exemplify how the typecheck function works, we implemented the factorial function as follows: Axioms 12 00043 i014 One could run the typecheck function on the term Fix factorial under the empty context (nil) with the Compute vernacular, and monitor the output that is commented out in the below snippet: Axioms 12 00043 i015 Of course, the below computation returns None as the term is ill-typed under the empty context: Axioms 12 00043 i016
  • Eval.v: includes the single-step and multi-step beta-reduction functions, respectively, named beta and evaln. Observe that in exactly 40 steps, the factorial function computes the value of factorial 7 to be 5040: Axioms 12 00043 i017 Unlikely, the below computation, Axioms 12 00043 i018 returns None as the input term is stuck.
  • Progress.v: contains the proof of Progress Theorem 1.
  • Preservation.v: includes the proof of Preservation Theorem 2.
  • Soundness.v: contains what it means for a term being stuck (Definition 6) alongside the proof of Soundness Theorem 3.

References

  1. Reynolds, J.C. Definitional Interpreters for Higher-Order Programming Languages. High. Order Symb. Comput. 1998, 11, 363–397. [Google Scholar] [CrossRef]
  2. Church, A. A Formulation of the Simple Theory of Types. J. Symb. Log. 1940, 5, 56–68. [Google Scholar] [CrossRef] [Green Version]
  3. The Coq Development Team. The Coq Proof Assistant Reference Manual; The Coq Development Team: Paris, France, 2018. [Google Scholar]
  4. Wright, A.K.; Felleisen, M. A Syntactic Approach to Type Soundness. Inf. Comput. 1994, 115, 38–94. [Google Scholar] [CrossRef] [Green Version]
  5. Poulsen, C.B.; Rouvoet, A.; Tolmach, A.; Krebbers, R.; Visser, E. Intrinsically-typed definitional interpreters for imperative languages. Proc. ACM Program. Lang. 2018, 2, 16:1–16:34. [Google Scholar] [CrossRef] [Green Version]
  6. Altenkirch, T.; Reus, B. Monadic Presentations of Lambda Terms Using Generalized Inductive Types. In Proceedings of the Computer Science Logic, 13th International Workshop, CSL ’99, 8th Annual Conference of the EACSL, Madrid, Spain, 20–25 September 1999; Flum, J., Rodríguez-Artalejo, M., Eds.; Springer: Berlin/Heidelberg, Germany, 1999; Volume 1683, Lecture Notes in Computer Science. pp. 453–468. [Google Scholar] [CrossRef]
  7. Reynolds, J.C. The Meaning of Types From Intrinsic to Extrinsic Semantics. BRICS Rep. Ser. 2000, 7, 1–35. [Google Scholar] [CrossRef] [Green Version]
  8. Augustsson, L.; Carlsson, M. An exercise in dependent types: A well-typed interpreter. In Workshop on Dependent Types in Programming, Gothenburg; 1999. Available online: https://www.semanticscholar.org/paper/An-exercise-in-dependent-types%3A-A-well-typed-Augustsson-Carlsson/5dae20b002f4e9d91e60db6af192c69d7fe764c6 (accessed on 4 September 2022).
  9. Rouvoet, A.; Poulsen, C.B.; Krebbers, R.; Visser, E. Intrinsically-typed definitional interpreters for linear, session-typed languages. In Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2020, New Orleans, LA, USA, 20–21 January 2020; Blanchette, J., Hritcu, C., Eds.; ACM: New York, NY, USA, 2020; pp. 284–298. [Google Scholar] [CrossRef] [Green Version]
  10. Darais, D.; Labich, N.; Nguyen, P.C.; Horn, D.V. Abstracting definitional interpreters (functional pearl). Proc. ACM Program. Lang. 2017, 1, 12:1–12:25. [Google Scholar] [CrossRef] [Green Version]
  11. Darais, D.; Might, M.; Horn, D.V. Galois transformers and modular abstract interpreters: Reusable metatheory for program analysis. In Proceedings of the 2015 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2015, part of SPLASH 2015, Pittsburgh, PA, USA, 25–30 October 2015; Aldrich, J., Eugster, P., Eds.; ACM: New York, NY, USA, 2015; pp. 552–571. [Google Scholar] [CrossRef] [Green Version]
  12. Sergey, I.; Devriese, D.; Might, M.; Midtgaard, J.; Darais, D.; Clarke, D.; Piessens, F. Monadic abstract interpreters. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’13, Seattle, WA, USA, 16–19 June 2013; Boehm, H., Flanagan, C., Eds.; ACM: New York, NY, USA, 2013; pp. 399–410. [Google Scholar] [CrossRef]
  13. Johnson, J.I.; Sergey, I.; Earl, C.; Might, M.; Horn, D.V. Pushdown flow analysis with abstract garbage collection. J. Funct. Program. 2014, 24, 218–283. [Google Scholar] [CrossRef] [Green Version]
  14. Glück, R. Simulation of Two-Way Pushdown Automata Revisited. In Proceedings of the Semantics, Abstract Interpretation, and Reasoning about Programs: Essays Dedicated to David A. Schmidt on the Occasion of his Sixtieth Birthday, EPTCS, Manhattan, KS, USA, 19–20 September 2013; Banerjee, A., Danvy, O., Doh, K., Hatcliff, J., Eds.; 2013; Volume 129, pp. 250–258. [Google Scholar] [CrossRef] [Green Version]
  15. Johnson, J.I.; Horn, D.V. Abstracting abstract control. In Proceedings of the DLS’14, Proceedings of the 10th ACM Symposium on Dynamic Languages, part of SLASH 2014, Portland, OR, USA, 20–24 October 2014; Black, A.P., Tratt, L., Eds.; ACM: New York, NY, USA, 2014; pp. 11–22. [Google Scholar] [CrossRef] [Green Version]
  16. Gilray, T.; Lyde, S.; Adams, M.D.; Might, M.; Horn, D.V. Pushdown control-flow analysis for free. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, St. Petersburg, FL, USA, 20–22 January 2016; Bodík, R., Majumdar, R., Eds.; ACM: New York, NY, USA, 2016; pp. 691–704. [Google Scholar] [CrossRef] [Green Version]
  17. Amin, N.; Rompf, T. Type soundness proofs with definitional interpreters. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Paris, France, 18–20 January 2017; Castagna, G., Gordon, A.D., Eds.; ACM: New York, NY, USA, 2017; pp. 666–679. [Google Scholar] [CrossRef] [Green Version]
  18. Pierce, B.C.; de Amorim, A.A.; Casinghino, C.; Gaboardi, M.; Greenberg, M.; Hriţcu, C.; Sjöberg, V.; Tolmach, A.; Yorgey, B. Programming Language Foundations; Software Foundations Series; Electronic textbook, 2022; Volume 2, Version 5.5; Available online: http://www.cis.upenn.edu/~bcpierce/sf (accessed on 1 August 2019).
  19. Koprowski, A. A Formalization of the Simply Typed Lambda Calculus in Coq; INRIA: Le Chesnay-Rocquencourt, France, 2006. [Google Scholar]
  20. Wei, G. A Soundness Proof of STLC by Definitional Interpreters in Agda. 2019. Available online: https://continuation.passing.style/blog/stlc-soundness.html (accessed on 1 August 2018).
  21. van Der Bilt, P.; STLC in Coq Extended with a Sound Big-Step Semantics, Functions as Closures and Records as Lists. Coq-Lang-Playarea. 2015. Available online: https://github.com/pvanderbilt/coq-lang-playarea (accessed on 1 August 2019).
  22. Barendregt, H. Introduction to Generalized Type Systems. J. Funct. Program. 1991, 1, 125–154. [Google Scholar] [CrossRef] [Green Version]
  23. Girard, J. The System F of Variable Types, Fifteen Years Later. Theor. Comput. Sci. 1986, 45, 159–192. [Google Scholar] [CrossRef] [Green Version]
  24. Coquand, T.; Huet, G.P. The Calculus of Constructions. Inf. Comput. 1988, 76, 95–120. [Google Scholar] [CrossRef] [Green Version]
  25. Moggi, E. Notions of Computation and Monads. Inf. Comput. 1991, 93, 55–92. [Google Scholar] [CrossRef] [Green Version]
  26. Nicolaas Govert de Bruijn. Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem. Indag. Math. Proc. 1972, 75, 381–392. [Google Scholar] [CrossRef]
  27. Charguéraud, A. The Locally Nameless Representation. J. Autom. Reason. 2012, 49, 363–408. [Google Scholar] [CrossRef]
  28. Chlipala, A. Parametric higher-order abstract syntax for mechanized semantics. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming, ICFP 2008, Victoria, BC, Canada, 20–28 September 2008; pp. 143–156. [Google Scholar] [CrossRef] [Green Version]
  29. Nigron, P.; Dagand, P. Reaching for the Star: Tale of a Monad in Coq. In Proceedings of the 12th International Conference on Interactive Theorem Proving, ITP 2021, Rome, Italy (Virtual Conference), 29 June–1 July 2021; Cohen, L., Kaliszyk, C., Eds.; Schloss Dagstuhl-Leibniz-Zentrum für Informatik: Wadern, Germany, 2021; Volume 193, LIPIcs. pp. 29:1–29:19. [Google Scholar] [CrossRef]
Figure 1. Extended Lambda terms.
Figure 1. Extended Lambda terms.
Axioms 12 00043 g001
Figure 2. Small-step CBV semantics.
Figure 2. Small-step CBV semantics.
Axioms 12 00043 g002
Figure 3. Type-extended Lambda terms.
Figure 3. Type-extended Lambda terms.
Axioms 12 00043 g003
Figure 4. Typing judgments.
Figure 4. Typing judgments.
Axioms 12 00043 g004
Figure 5. Typing-adapted small-step CBV semantics.
Figure 5. Typing-adapted small-step CBV semantics.
Axioms 12 00043 g005
Figure 6. Dependency among proof terms.
Figure 6. Dependency among proof terms.
Axioms 12 00043 g006
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Ekici, B. A Sound Definitional Interpreter for a Simply Typed Functional Language. Axioms 2023, 12, 43. https://doi.org/10.3390/axioms12010043

AMA Style

Ekici B. A Sound Definitional Interpreter for a Simply Typed Functional Language. Axioms. 2023; 12(1):43. https://doi.org/10.3390/axioms12010043

Chicago/Turabian Style

Ekici, Burak. 2023. "A Sound Definitional Interpreter for a Simply Typed Functional Language" Axioms 12, no. 1: 43. https://doi.org/10.3390/axioms12010043

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop