Chris Barker

Hugo Herbelin

Myriam Quatrini

Christina Unger

Clément Beysson

Sarah Blind

Anh Vu

Bruno Duc

Nicolas Guillaume

Pierre Lefebvre

Aleksandre Ludmann

Guy Maskharashvili

Sylvain Perrier

Sai Pogodalla

Stéphane Tiv Qian

Mihai Andries

Benoît Chappet De Vangel

Émilie Colin

Sylvain Contassot-Vivier

Baldwin Dumortier

Mariia Fedotenkova

Iñaki Fernández Pérez

Francesco Giovannini

Arseniy Gorin

Meysam Hashemi

Adrien Krähenbühl

Cecilia Lindig-Leon

Jérémy Miranda

Aybüke Özgün

Motaz Saad

Yann Salaun

Evangelia Tsiontsiou

Jan Volec My

Maxime Amblard

Philippe De Groote

Bruno Guillaume

Guy Perrier

Bruno Andriamiarina Miharimanana

Georgy Boytchev

Caroline Ceballos

Tatiana Ekeinhor-Komi

Nicolas Feuillet

Natalia Korchagina

Imane Nkairi

Gabin Personeni

Wei Qiu

Camille Sauder During

Lasha Abzianidze

Eleri Aedmaa

Pepijn Kokke

Stellan Petersson

B Example from the Final Fragment C Computer Mechanization of the Calculus

I would like to thank my supervisors, whose contributions have been essential

Introduction

The motivation behind this thesis is to advance the automatic process of translating natural language into logical representations. The interest behind this translation procedure is two-fold: linguists use it to give a formal semantics to natural languages and computer scientists use it to perform automated reasoning on natural language data.

There has been considerable research into translating parts of English and other natural languages. When looking at a sentence of English, we can identify many of the problems inherent in the translation and point to papers that have proposed solutions.

(1) She might still be dating that idiot.

1. We have anaphoric expressions, such as the pronoun she. We know that we can translate sentences with anaphora into Discourse Representation Theory (DRT) structures [64], Dynamic Predicate Logic (DPL) formulas [53] or continuation-passing style λ-terms [38].

2. We have the modal auxiliary might that we can translate into an operator of modal logic or directly to some existential quantification over possible worlds.

3. We have the progressive present tense in be dating. Similarly to the modal, we can translate this into an operator of temporal logic or directly posit the existence of some interval of time during which the dating takes place and assert that the time of utterance (possibly) lies in that interval.

4. We have the presupposition trigger still that tells us that the two subjects must have been dating in the past already. We will have to possess some mechanism to project this contribution outside the scope of any of the logical operators present. [START_REF]Continuations -racket reference[END_REF] We can adopt the strategy of Lebedeva [80] and raise exceptions to perform the projection.

5. We have the expressive epithet idiot. Following the theory of conventional implicatures of Potts [108], elaborated by Gutzmann [54], we know that we should introduce a second dimension into which we tuck away the speaker's negative attitude towards the date-ee so that it does not interfere with the at-issue content.

All of the advice given above seems sound. We could follow these guidelines to intuitively arrive at some reasonable logical representation. Now how do we write down this joint translation process? Most of the theories mentioned above come with their own language: their own definitions, notation and operations.

DRT introduces its own encoding of logical formulas and states an algorithm that builds them up incrementally from the input sentence [64]. Potts's logic of conventional implicatures introduces twodimensional logical formulas and defines new modes of combination to compute with them [108]. Compositional treatments of intensionality or tense tend to use the simply-typed lambda calculus [18, 40], as is also the case in de Groote's treatment of anaphora [38]. In studying presuppositions, Lebedeva uses a modified version of de Groote's calculus which includes exceptions [80].

It seems clear that in order to arrive at a precise notion of what it means do all of 1-5, we will first have to be able to express the theories behind 1-5 using a common formal language.

2

Introduction

Enter Monads

We will base our universal language on the λ-calculus. Thanks to Richard Montague's hugely influential work [98], the λ-calculus is already a very popular formalism in formal compositional semantics. 2 Many phenomena are analyzed using the λ-calculus and the rest tend to get translated to λ-calculus as well (see, for example, λ-DRT [79] or de Groote's continuation-based approach to dynamics [38]).

However, even though we have several theories which are all formalised in λ-calculus, it does not necessarily mean that they are compatible or that we know how to combine them together. A theory of intensionality might state that sentences ought to be translated to terms that have the type σ → o, the type of functions from possible worlds to truth values. On the other hand, an account of expressives would argue that sentences ought to correspond to terms of type o × ϵ, the type of pairs of truth values (propositional content) and expressive markers (expressive content). The two theories would be compatible at the calculus-level but not at the term-level. A function operating with intensional propositions would not be directly applicable to an expressive proposition.

To continue our quest for uniformity and compatibility of semantic operations, we will look at the terms and types used by the different λ-theoretic treatments of semantics and try to find a common structure underneath. We notice that all such approaches share at least the following structure:

1. The types of some of the denotations get expanded. For example, when dealing with quantifiers, the type of denotations of noun phrases goes from ι (single individuals) to (ι → o) → o (generalized quantifiers over individuals); in intensional semantics, the type of denotations of sentences goes from o (truth values) to σ → o (functions from possible worlds to truth values, i.e. sets of possible worlds); and with expressives, the type of denotations of sentences goes from o to o×ϵ (truth values coupled with expressive markers).

2. There is a process that can lift denotations of the old type into denotations of the new type. In the quantifier example, this is the famous type raising operation. In the intensional example, this is the K combinator that turns a truth value into a constant function that assigns that truth value to all worlds, a rigid intension. In the expressive example, this is the function that couples a proposition with a neutral/empty expressive marker.

3. Then there are other inhabitants of the expanded type that are not found by using the lifting function described above; those are the ones for which we expanded the type. Quantificational noun phrases such as everyone are not the result of type raising any specific individual. Intensional propositions such as Hespherus is Phosphorus have extensions that vary from world to world. Expressives such as the diminutive Wolfie will point to some individual and also carry some expressive marker that conveys the speaker's attitude towards the referent.

4. Finally, these approaches also have some general way of composing smaller denotations into larger ones and dealing with the added complexity caused by the more elaborate types. When applying a transitive verb to a quantificational subject and object, we let one (often the subject) first take scope and then we let the other take scope. When applying the verb to intensional arguments, we pass the world at which we are evaluating the sentence down to both the subject and the object. When applying it to expressive arguments, we apply the verb to the referents of both the subject and the object and on the side we collect the expressive content of both.

This kind of structure is very commonly seen in functional programming and in denotational semantics of programming languages. It is the structure of an applicative functor [91] (or strong lax monoidal functor, for the categorically-inclined). The above examples are also instances of a more special structure called a monad [95].

We will not go into the minutiae of the definition of a monad here but we will give a rough sketch nonetheless. A monad is a triple (T, η, ≫=) where T is a function on types (the type expansion we saw in 1), η is some way of lifting simple values into expanded values (the lifting functions in 2) and ≫= gives us a general way of combining values of this expanded type (similar to the examples given in 4). 3 The triple also has to satisfy some algebraic properties which guarantee that composing functions of expanded types is associative and that the lifting function serves as a unit for this composition operator.

The examples given above are all instances of monads. The prevalence of monads in natural language semantics has been already discovered by Shan in [113]. However, the challenge lies in trying to use several monads at the same time.

Linguistic Side Effects

Monads often appear in denotational semantics of programming languages to account for notions of computation commonly referred to as side effects [95]. We can base ourselves on this correspondence and regard the monadic structure in natural language as linguistic side effects. This analogy was pursued by Shan [115, 116] and Kiselyov [67] and is present in recent work on monads in natural language semantics [48, 27]. However, the idea itself stretches back before monads were even introduced to computer science. In their 1977 paper [57], Hobbs and Rosenschein take a computational perspective on the intensional logic of Montague [98]: intensions correspond to programs and extensions correspond to values. A program can read the value of global variables that describe the state of the world. 4 The operators ↑ and ↓, which map between extension-denoting expressions and intension-denoting expressions, then correspond to the Lisp-style operators quote and eval respectively.

The idea of treating linguistic expressions as effectful actions or programs is also very relevant to dynamic semantics, which treats the meanings of sentences as instructions to update some common ground or other linguistic context. 5 Dynamic semantics and anaphora are sometimes classified as belonging to both semantics and pragmatics. This is also the case for other phenomena that we will treat as side effects in our dissertation: deixis, presupposition, conventional implicature. Pragmatics studies the way a language fits into the community of its users, i.e. how it is actually used by its speakers to achieve their goals. It might then come as no surprise that pragmatics align well with side effects in programming languages since side effects themselves concern the ways that programs can interact with the world of their users (e.g. by making things appear on screen or by listening for the user's input).

Effects and Handlers

By looking at the different monadic structures of natural language semantics as side effects, we can apply theories that combine side effects to find a formalism that can talk about all the aspects of language at the same time. One such theoretical framework are effects and handlers. In this framework, programs are interpreted as sequences of instructions (or more generally as decision trees). [START_REF] Andjelkovic | Towards indexed algebraic effects and handlers[END_REF] The instructions are symbols called operations, which stand for the different effects, the different ways that programs can interact with their contexts. In our application to natural language semantics, here are some examples of operations that will feature in our demonstrations, along with their intended semantics: [START_REF] Appel | Higher-order (non-) modularity[END_REF] • introduce introduces a new discourse referent to the context. This is the kind of operation used by noun phrases such as the indefinite a man.

• presuppose P presupposes the existence of an entity satisfying the predicate P . This is used by definite descriptions the P and by proper nouns.

4

Introduction

• implicate i states that i is a conventional implicature. This operation is used by appositive constructions such as John, who is my neighbor.

• speaker asks the context for the identity of the speaker. This is used by the first-person pronoun to find its referent.

The process of calculating the denotation of a linguistic expression is broken down to these operations. When expressions combine to form sentences and discourses, these operations end up being concatenated into a large program which will want to perform a series of interactions with its context. This is when handlers come into play. A handler is an interpreter that gives a definition to the operation symbols in a program. Handlers can be made modular [START_REF] Asher | Logics of conversation[END_REF] so that the interpreter for our vocabulary of context interactions can be defined as the composition of several smaller handlers, each treating a different aspect of language (dynamicity, implicatures, deixis…).

When using effects and handlers, we therefore start by enumerating the set of interactions that programs (i.e. linguistic expressions in our application) can have with their contexts. Then, we can interpret linguistic expressions as sequences of such instructions. Finally, we write handlers which implement these instructions and produce a suitable semantic representation. This approach thus closely follows the mantra given by Lewis:

In order to say what a meaning is, we may first ask what a meaning does and then find something that does that. General Semantics, David Lewis [83] We can trace the origins of effects and handlers to two strands of work. One is Cartwright and Felleisen's work on Extensible Denotational Language Specifications [24], in which a technique for building semantics is developed such that when a (programming) language is being extended with new constructions (and new side effects), the existing denotations remain compatible and can be reused. The other precursor is Hyland's, Plotkin's and Power's work on algebraic effects [60], a categorical technique for studying effectful computations, which was later extended by Plotkin and Pretnar to include handlers [103, 110, 104]. The technique has gained in popularity in recent years (2012 and onward). It finds applications both in the encoding of effects in pure functional programming languages [71, 70, 63, 22] and in the design of programming languages [16, 87, 41, 73, 56]. Our thesis will explore the applicability of effects and handlers to natural language semantics.

Plan

The manuscript of this thesis is split into two parts. In the first, we develop a formal calculus that extends the simply-typed lambda calculus with a free monad for effects and handlers. We prove some key properties, such as strong normalization, and we show how the calculus relates to other similar notions such as continuations or monads. In the second part, we analyze some of the aspects of linguistic meaning as side effects: deixis, conventional implicature, quantification, anaphora and presupposition. We then incrementally build up a fragment that features all of those features and demonstrates some of their interactions.

Part I

Calculus of Effects and Handlers

We will present a calculus with special constructions for dealing with effects and handlers, which we will then apply to the problem of natural language semantics in the second part of the thesis. Our calculus, which we will call λ , is an extension of the simply-typed λ-calculus (STLC). We enrich STLC with a type for representing effectful computations alongside with operations to create and process values of this type.

Definitions

We are tempted to start by first giving the formal definitions of all the essential components of λ :

• the syntax of the terms in λ

• the syntax of the types in λ

• the judgments that relate types to terms • the reduction semantics However, before we do so, we will briefly sketch the ideas behind λ so you can start building an intuition about the meaning of the symbols that we will be introducing below.

We will be adding a new type constructor, F, into our language. The type F(α) will correspond to effectful computations that produce values of type α. The idea comes from the programming language Haskell and its use of monads [95, 133, 62]. Our type constructor F will also stand in for a monad, one that has been already encoded in Haskell in several ways [71, 63]. The motivation behind λ is to build a minimal language which directly gives us the primitive operations for working with this particular monad. This way, we end up with a language that:

• is smaller than Haskell (and thus more mananageable to analyse),

• is closer to the STLC favored by semanticists, 8 Chapter 1. Definitions

• and which makes more evident the features that our proposal relies on.

The transition from type α to a type F(α) is meant as a generalization of a scheme often seen in semantics when novel forms of meaning are studied (e.g., type raising [98], dynamization [80], intensionalization [40]). The distinction between the type α and the type F(α) will, in different analyses, align with dichotomies such as the following:

• reference/sense • static/dynamic meaning

• extension/intension • semantics/pragmatics

The question then is, what form should our general F type constructor take? We want to have a construction that can combine all the existing ones. One can do the combining at the level of monads with the use of monad transformers, a technique pioneered by Moggi and very well-established in the Haskell programming community [95]. Simon Charlow has made the case that this technique can be exploited to great benefit in natural language semantics as well [27].

However, a competing technique has emerged in recent years and it is the goal of this thesis to introduce it to semanticists and verify its applicability to the study of natural language. The technique goes by many names, "algebraic effects and handlers" and "extensible effects" being the most commonly used ones. This is in part due to the fact that it lies at the confluence of several research programs. This fact will allow us to present the theory from two different perspectives so you can be equipped with two different intuitive models.

Algebraic Effects and Handlers

Hyland, Power and Plotkin have studied the problem of deriving denotational semantics of programming languages that combine different side effects [60]. In their approach, rather then modeling the individual effects using monads and combining the monads, every effect is expressed in terms of operators on computations. Computations thus become algebraic expressions with effects as operations and values as part of the generator set. Let us take the example of nondeterminism. In the monadic framework, this effect is analyzed by shifting the type of denotations from α to the powerset P(α). In the algebraic framework, a binary operator + is introduced and is given meaning through a set of equations. In this case, these are the equations of a semilattice (stating the operator's associativity, commutativity and idempotence).

When the time comes to combine two effects, their signatures are summed together and their theories are combined through either a sum or a tensor (tensor differs from sum in that it adds commutativity laws for operators coming from the two different effects).

In order to fit exception handlers into their theory, Plotkin and Pretnar enriched the theory with a general notion of a handler [104]. A handler's purpose is to replace occurrences of an operator within a computation by another expression. This notion was shown to be very useful. Since using a handler on a computation is similar to interpreting its algebraic expression in a particular algebra, in many practical applications, the use of handlers has replaced equational theories altogether [16, 63, 22].

Extensible Effects

In the early 90's, Cartwright and Felleisen were working on the following problem. Imagine you have a simple programming language along with some denotational semantics or some other interpretation. In your simple language, numerical expressions might be interpreted as numbers. In that case, the literal number 3 would denote the number 3 and the application of the sum operator to two numerical expressions would denote the sum of their interpretations. Now imagine that you want to add mutable variables to your language. Numerical expressions no longer denote specific numbers, but rather functions from states of the variable store to both a number and an updated variable store (since expressions 1.2. Terms can now both read from and write to variables). The number 3 is thus no longer interpreted as the number 3 but as a combination of a constant function yielding the number 3 and an identity function. The addition operator now has to take care to thread the state of the memory through the evaluation of both of its arguments. In short, we are forced to give new interpretations for the entire language.

Cartwright and Felleisen proposed a solution to this problem [24]. In their system, an expression can either yield a value or produce an effect. If it produces an effect, the effect percolates through the program all the way to the top, with the context that the effect projected from stored as a continuation. The effect and the continuation are then passed to an external "authority" that handles the effect, often by producing some output and passing it back to the continuation. When a new feature is added to the language, it often suffices to add a new kind of effect and introduce a new clause into the central "authority". The central authority then ends up being a collection of small modular interpreters for the various effect types. Denotation-wise, every expression can thus have a stable denotation which is either a pure value or an effect request coupled with a continuation.

Later on, this project was picked up by Kiselyov, Sabry and Swords, who, following Plotkin and Pretnar's work on handlers, proposed to break down the "authority" into the smaller constituent interpreters and have them be part of the language themselves [71].

Synthesis

In our language, values of type F(α) can be seen either as algebraic expressions or as programs. Under the algebraic perspective, an expression is either a variable or an operator applied to some other expressions, whereas under the "extensible effects" perspective, a program is either a value or a request for an effect followed by some other programs (the continuation).

Our calculus will also have a special form for defining handlers. In the "algebraic effects and handlers" frame of mind, these can be thought of as algebras that interpret the operations within an algebraic expression. On the other hand, with "extensible effects", the intuition is more similar to that of an exception handler which intercepts requests of a certain type and decides how the computation should continue.

Terms

Having sketched the idea behind our calculus, we will now turn our attention to the specifics. We start by defining the syntactic constructions used to build the terms of our language.

Without further ado, we give the syntax of the expressions of our language. First off, let X be a set of variables, Σ a typed signature and E a set of operation symbols.

The expressions of our language are comprised of the following: The first four constructions -variables, constants, abstractions and applications -come directly from STLC with constants.

The next four deal with the algebraic expressions used to encode computations. Let us sketch the behaviors of these four kinds of expressions under the two readings outlined above.

Algebraic Expressions -The Denotational View

The set of algebraic expressions is generated by closing some generator set over the operations of the algebra. The η function serves to inject values from the generator set into the set of algebraic expressions. It is the constructor for the atomic algebraic expressions.

Next, for every symbol op in E, we have a corresponding constructor op in our calculus. op is a constructor for algebraic expressions whose topmost operation is op. The op constructor takes as argument a function that provides its operands, which are further algebraic expressions.

The banana brackets op 1 : M 1 , . . . , op n : M n , η: M η contain algebras: interpretations of operators and constants. These components are combined into a catamorphism that can interpret algebraic expressions (hence the use of banana brackets [93]) [START_REF] Balat | Extensional normalisation and type-directed partial evaluation for typed lambda calculus with sums[END_REF] .

The extraction function -• , pronounced "cherry", takes an atomic algebraic expression (the kind produced by η) and projects out the element of the generator set.

Effectful Computations -The Operational View

We will now explain these constructions from the computational point of view.

The η function "returns" a given value. The result of applying it to a value x is a computation that immediately terminates and produces the value x.

The symbols from E become something like system calls. A computation can interrupt its execution and throw an exception with a request to perform a system-level operation. For every symbol op in E, there is a constructor op that produces a computation which issues a request to perform the operation op. This constructor takes as an argument a continuation which yields the computation that should be pursued after the system-level operation op has been performed.

The banana brackets op 1 : M 1 , . . . , op n : M n , η: M η describe handlers: they contain clauses for different kinds of interrupts (operation requests) and for successful computations (clause η). They behave very much like handlers in languages with resumable exceptions such as Common Lisp or Dylan.

Finally, the cherry function -• can take a computation that is guaranteed to be free of side effects and run it to capture its result. The 9th construction in our calculus is the C operator. C serves as a link between the function type discussed by STLC (constructions 1-4) and the computation type introduced in our calculus (constructions 5-8). C is a (partial) function that takes a computation that produces a function and returns a function that yields computations. In a way, C makes abstracting over a variable and performing an operation commute together [START_REF] Barendregt | The lambda calculus: its syntax and semantics[END_REF] .

We will see the utility of C later on. The idea came to us from a paper by Philippe de Groote [39] which tried to solve a similar problem. The name comes from the C combinator, which reorders the order of abstractions in a λ-term.

Types and Typing Rules

We now give a syntax for the types of λ alongside with a typing relation. In the grammar below, ν ranges over atomic types from a set T .

The types of our language consist of: function α → β, where α and β are types atom ν, where ν is an atomic type from T computation F E (α), where α is a type and E is an effect signature (defined next)

The only novelty here is the F E (α) computation [START_REF] Barker | Continuations in natural language[END_REF] type. This type will be inhabited by effectful computations that have permission to perform the effects described in E and yield values of type α. The representation will be that of an algebraic expression with operators taken from the signature E and generators of type α.

In giving the typing rules, we will rely on the standard notion of a context. For us, specifically, a context is a partial mapping from the variables in X to the types defined above. We commonly write Γ, x : α for a context that assigns to x the type α and to other variables y the type Γ(y). We also write x : α ∈ Γ to say that the context maps x to α. Note, however, that for ∆ = Γ, x : α, x : β, we have x : β ∈ ∆ while x : α / ∈ ∆. Effect signatures are very much like contexts. They are partial mappings from the set of operation symbols E to pairs of types. We will write the elements of effect signatures the following way: op : α ↣ β ∈ E means that E maps op to the pair of types α and β. [START_REF] Barker | Continuations and the nature of quantification[END_REF] When dealing with effect signatures, we will often make use of the disjoint union operator ⊎. The term E 1 ⊎E 2 serves as a constraint demanding that the domains of E 1 and E 2 be disjoint and at the same time it denotes the effect signature that is the union of E 1 and E 2 .

The last kind of dictionary used by the type system is a standard higher-order signature for the constants (a map from names of constants to types). For those, we adopt the same conventions.

In our typing judgments, contexts will appear to the left of the turnstile and they will hold information about the statically (lexically) bound variables, as in STLC. Effect signatures will appear as indices of computation types and they will hold information about the operations that are dynamically bound by handlers. Finally, there will be a single higher-order signature that will globally characterize all the available constants.

The typing judgments are presented in Figure 1.1. Metavariables M , N … stand for expressions, α, β, γ… stand for types, Γ, ∆… stand for contexts, op, op i stand for operation symbols and E, E ′ … stand for effect signatures. Σ refers to the higher-order signature giving types to constants. The typing rules mirror the syntax of expressions. Again, the first four rules come from STLC. The next four deal with introducing pure computations, enriching them with effectful operations, handling those operations away and finally eliminating pure computations. The C rule lets us start to see what we meant by saying that the C operator lets the function type and the computation type commute.

Let us ponder the types of the new constructions so as to get a grip on the interface that the calculus provides us for dealing with computations.

[η]

First off, we have the η operator. It takes a value of type α and injects it into the type F E (α). The metavariable E is free, meaning η can take values of type α to type F E (α) for any E. The algebraic intuition would say that elements of the generator set are valid algebraic expressions independent of the choice of signature. Computationally, returning a value is always an option, independently of the available permissions.

[op]

More complicated computations can be built up by extending existing computations using the operation construction. Let us have an effect signature E such that op : α ↣ β ∈ E. To use op, we first apply it 12 Chapter 1. Definitions to a value of the input type α and to a continuation. The continuation is a function of type β → F E (γ) that accepts a value of the output type β (the result of performing the operation) and chooses in return a computation that should be pursued next. The return type of our new computation will thus be the return type γ of the computation provided by the continuation. The continuation's computation and the new extended computation will also share the same effect signature E. This means that all uses of the operation op within the created computation have the same input and output types. [START_REF] Barker | Monads for natural language[END_REF] There is a parallel between the [var] rule and the [op] rule. The [var] rule lets use a symbol x with type α provided x : α ∈ Γ. The [op] rule lets use a symbol op with type α → (β → F E (γ)) → F E (γ) provided op : α ↣ β ∈ E. The crucial difference is that contexts (Γ) are components of judgments whereas effect signatures (E) are components of types. The meaning of a variable is determined by inspecting the expression in which it occurs and finding the λ that binds it (this is known as lexical or static binding). On the other hand, the meaning of an operation in a computation is determined by evaluating the term in which the computation appears until the computation becomes the argument of a handler. This handler will then give meaning to the operation symbol by substituting it with a suitable interpretation (this kind of late binding is known as dynamic binding).

x : α ∈ Γ [var] Γ ⊢ x : α c : α ∈ Σ [const] Γ ⊢ c : α Γ, x : α ⊢ M : β [abs] Γ ⊢ λx. M : α → β Γ ⊢ M : α → β Γ ⊢ N : α [app] Γ ⊢ M N : β Γ ⊢ M : α [η] Γ ⊢ η M : F E (α) Γ ⊢ M p : α Γ, x : β ⊢ M c : F E (γ) op : α ↣ β ∈ E [op] Γ ⊢ op M p (λx. M c ) : F E (γ) Γ ⊢ M : F ∅ (α) [ -• ] Γ ⊢ -• M : α E = {op i : α i ↣ β i } i∈I ⊎ E f E ′ = E ′′ ⊎ E f [Γ ⊢ M i : α i → (β i → F E ′ (δ)) → F E ′ (δ)] i∈I Γ ⊢ M η : γ → F E ′ (δ) Γ ⊢ N : F E (γ) [ ] Γ ⊢ (op i : M i ) i∈I , η: M η N : F E ′ (δ) Γ ⊢ M : α → F E (β) [C] Γ ⊢ C M : F E (α → β)
We have now seen how to construct pure computations using η and extend them by adding operations. However, before we go on and start talking about handlers, we would like to give the algebraic intuition behind [op], as the algebraic point of view makes explaining the handler rule [ ] easier.

We can see the effect signature as an algebraic signature. For every op : α ↣ β ∈ E, we have an α-indexed family of operators of arity β. Let's unpack this statement.

• First, there is the matter of having an indexed family of operators. A common example of these is the case of scalar multiplication in the algebra of a vector space. A single-sorted algebraic signature is a set of operation symbols, each of which is given an arity (a natural number). For vector addition, the arity is 2, since vector addition acts on two vectors (two elements of the domain). Scalar multiplication acts on one scalar and one vector. However, neither arity 1 nor arity 2 adequately express this. We can get around the limitations of a single-sorted signature by introducing for every scalar k an operation of arity 1 that corresponds to multiplying the vector by k. Scalar multiplication is therefore not a single operator but a scalar-indexed family of operators.

The very same strategy is applied here as well. A single operation symbol doesn't need to map to a single operator but can instead map to (possibly infinitely) many operators indexed by values of some type α. For example, writing messages to the program's output (print : string ↣ 1) can be seen as a string-indexed family of unary operators on computations. For every string s, we get an operator that maps computations c to computations that first print s and then continue as c.

• Next, we were speaking about operators of arity β. The use of a type in place of a numerical arity is due to a certain generalization. In set theory, natural numbers become sets that have the same cardinality as the number they represent (|N | = N ). We can therefore conservatively generalize the idea of arity to a set by saying that an operator of arity X takes one operand per each element of the set X. It's a short step from there to using types as arities, wherein an operator of arity β takes one operand per possible value of type β.

This will come in very handy in our system. We want our operator op to have as many operands as there are possible values in the output type β. Therefore, we simply say that the operator has arity β.

How do we write down the application of an operator of arity β to its operands? We can no longer just list out all the operands, since types in λ may have an unbounded number of inhabitants. We will organize operands in operand clusters, [START_REF] Barker | Continuations and natural language[END_REF] arity-indexed families of operands. We will write them down as functions, using λ-abstraction, from the arity type β to some operand type, e.g., F E (γ).

Now we can understand what it means to say that op : α ↣ β ∈ E gives rise to an α-indexed family of operators of arity β. We apply to op an index of type α to get an operator and then we apply that operator to an operand cluster of type β → F E (γ) to get a new expression of type F E (γ).

We suggest visualizing these algebraic expressions as trees (see Section 2 of [86] for the original idea). Trees of type F E (α) consist of leafs containing values of type α and internal nodes labelled with operations and their parameters. Every internal node is labelled with some op : α ↣ β ∈ E and with a parameter of type α and it has a cluster of children indexed by β.

[ ]

Now we are ready to explain the handler rule. The typing rule for is repeated in Figure 1.2. To illustrate the constraints on the types of the components, M i and M η , of a handler, we will examine its semantics. The handler processes the algebraic expression N by recursive induction. Depending on the shape of the expression, one of the following will happen:

• If N = η N ′ , then N ′ is of type γ. This is where the M η function comes in. It must take a value of type γ and produce a new tree of type F E ′ (δ), hence the fourth hypothesis of the rule.

• If N = op i N p (λx. N c ) for some i ∈ I, then N p must be of type α i . Furthermore, for every x : β i , we have an operand N c : F E (γ). We know this since N is of type F E (γ) and the first hypothesis tells us that op i : α i ↣ β i ∈ E.

We will recursively apply our handler to the cluster of operands, changing their type from F E (γ) to F E ′ (δ). We now need something which takes N p , whose type is α i , and the cluster of processed operands, type β i → F E ′ (δ), which is exactly the function M i in the third hypothesis of the rule.

• If N = op N p (λx. N c ) and op : α ↣ β ∈ E f for some α and β, then we will ignore the node and process only its children. This means that the resulting expression will contain the operation symbol op from E f [START_REF] Bauer | Lambda the ultimate -programming with algebraic effects and handlers[END_REF] . In order for such an expression to be of the desired type F E ′ (δ), E f must be included in E ′ , which is what the second hypothesis of the rule guarantees. We have covered the whole rule, except for the presence of the effect signature E ′′ . It serves two roles.

E = {op i : α i ↣ β i } i∈I ⊎ E f E ′ = E ′′ ⊎ E f [Γ ⊢ M i : α i → (β i → F E ′ (δ)) → F E ′ (δ)] i∈I Γ ⊢ M η : γ → F E ′ (δ) Γ ⊢ N : F E (γ) [ ] Γ ⊢ (op i : M i ) i∈I , η: M η N : F E ′ (δ)
• First of all, it acts as a "free" variable over effect signatures. This means that we can give any effect signature E ′ to the type F E ′ (δ) of the resulting computation N ′ as long as E ′ contains E f (E ′′ represents the relative complement of E f in E ′ ). This is in analogy to the free effect variable E in the [η] and [op] rules. This freedom of effect variables is a way of implementing the idea that a computation of type F E1 (α) can be used anywhere that a computation of type F E2 (α) is needed given that E 1 ⊆ E 2 .

• In the previous paragraph, why did we put the word "free" in quotation marks? Because the effect variable E ′′ is not actually free. It is the complement of E f in E ′ and E ′ is constrained by the types of M i and M η in the third and fourth hypotheses, respectively. The handler's clauses might themselves introduce new effects, which will in turn translate into constraints on E ′ and E ′′ . This happens when a handler interprets an operation by making an appeal to some other operation (e.g. a handler could interpret computations using n-ary choice into computations using binary choice).

As the simplest example, we can take a handler that replaces one operation symbol with another, old: (λpc. new p (λy. c y)), η: (λx. η x) . The type scheme corresponding to the term is F {old:α↣β}⊎E f (γ) → F {new:α↣β}⊎E + ⊎E f (γ). In this scheme, α, β and γ are free meta-variables ranging over types and E f and E + range over effect signatures. The E ′′ of the rule corresponds to {new : α ↣ β} ⊎ E + (i.e. E ′′ is not free, it must contain new). The handler has eliminated the old effect but it has also introduced the new effect. This concludes our exploration of the rule. We have explained it in terms of algebraic expressions and trees, using the denotational intution. We will develop the operational intuition, which talks about handlers in terms of computations and continuations, in Section 1. 4, where we will give the semantics of our language using reduction rules.

[cherry]

Next up is the cherry operator, -• . Its type is F ∅ (α) → α and it serves as a kind of dual to the η opertator, an elimination for the F type.

The type F ∅ (α) demands that the effect signature be empty. In such a case, the tree has no internal nodes and is composed of just a leaf containing a value of the type α. The -• operator serves to extract that value.

Another way to look at it is to say that a computation of type F ∅ (α) cannot perform any "unsafe" operations and it is therefore always safe to execute it and get the resulting value of type α.

[C]

Finally, we take a look at the C operator. The type of the operator is (α → F E (β)) → F E (α → β). Its input is an α-indexed family of computations and its output is a computation of α-indexed families. The operator applies only in the case when all the computations in the family share the same internal structure. By sharing the same internal structure, we mean that the trees can only differ in their leaves. What the C operator then does is to push the λ-binder down this common internal structure into the leaves. This way, we can evaluate/handle the common operations without commiting to a specific value of type α.

The action of the C operator is illustrated in Figure 1.3. Here, M is a function of some two-value type. It maps one value to the left subtree of λ (with leaves A i ) and the other value to the right subtree (leaves B i ). Both subtrees correspond to computations, in which a box is an operation and a circle is an atomic expression (i.e. a return value). Furthermore, op 1 has a two-value output type (arity 2) and op 2 has a one-value output type (arity 1).

Since the operations op 1 and op 2 and their arguments M 1 and M 2 are the same in both subtrees, and thus independent of the value passed to the λ, we can apply the C operator. The C pulls this common structure out of the λ and gives us a computation that produces a function.

We can also explain the action of C in operational terms. As in call-by-push-value [82], we can think of abstraction over α as some effectful operation that tries to pop a value x : α off a stack. The input of C can then be seen as a continuation waiting for this x and wanting to perform some further operations. C assumes that the continuation performs operations independently of x [START_REF] Bauer | Programming with algebraic effects and handlers[END_REF] and it can thus postpone popping x off the stack until after the operations dictated by the continuation have been evaluated. C is therefore a kind of commutativity law for operations and abstractions (the popping of a value off the operand stack): as long as one does not depend on the other, it does not matter whether we first perform an operation and then abstract over an argument or whether we do so the other way around. [START_REF] Beaver | Presupposition[END_REF]

Reduction Rules

We will now finally give a semantics to λ . The semantics will be given in the form of a reduction relation on terms. Even though the point of the calculus is to talk about effects, the reduction semantics will have no notion of order of evaluation; any reducible subexpression can be reduced in any context.

Before we dive into the reduction rules proper, we will first have to handle some formal paperwork, most of it due to the fact that we use variables and binders in our calculus. In order to quotient out the irrelevant distinction between terms that are the same up to variable names, we will introduce a series of definitions leading up to a notion of α-equivalence. FV( (op i :

M i ) i∈I , η: M η N ) = ∪ i∈I FV(M i ) ∪ FV(M η ) ∪ FV(N ) FV( -• M ) = FV(M ) FV(C M ) = FV(M )
Most often, we will make use of FV indirectly, using the following notion. Definition 1.4.2. We say that x is fresh for M iff x / ∈ FV(M ).

(η M )[x := N ] = η (M [x := N ]) ( (op i : M i ) i∈I , η: M η N ′ )[x := N ] = (op i : (M i [x := N ])) i∈I , η: (M η [x := N ]) (N ′ [x := N ]) ( -• M )[x := N ] = -• (M [x := N ]) (C M )[x := N ] = C (M [x := N ])
Note that it is possible for M [x := N ] to not be defined by the equations above (e.g. (λy. x)[x := y]). In such cases, we say that the substitution does not exist.

• if M [∼] M ′ , then C[M ] [∼] C[M ′ ]
We will be defining relations on the terms of λ that will correspond to different transformations (such as swap and the reduction rules). The notion of context closure will allow us to say that a term can be transformed by transforming any of its parts. The notion of α-equivalence will be very useful. We will use it so much that we will actually quotient the set of terms and start talking about α-equivalence classes instead of specific terms. We will keep using the same notation and so from now on, terms written in the syntax of our calculus no longer designate individual terms but rather α-equivalence classes of terms. The term "term" will itself be freely used to actually mean an α-equivalence class of terms.

Chapter 1. Definitions

However, before we start using individual terms while having them represent entire α-equivalence classes, we should better make sure that the operations that we will perform with these terms are congruent with α-equivalence. [START_REF] Ben | The semantics of intensionalization[END_REF] Is it the case that the operations we have introduced in this section are congruent with α-equivalence?

FV is congruent: swapping names bound by λ does not change the set of free variables in a term. What about substitution? As we have already seen, capture-avoiding substitution is a partial operation:

(λy. x)[x := y] does not exist. However, λz. x is α-equivalent to λy. x and (λz. x)[x := y] exists; it is λz. y. Therefore, capture-avoiding substitution is not α-congruent.

We will introduce an alternative notion, capture-resolving substitution. While capture-avoiding substitution was a partial function on terms, capture-resolving substitution will be a total function on αequivalence classes of terms. Furthermore, the new function will be an extension of the old one. If capture-avoiding substitution would have mapped A to B, then capture-resolving substitution will map the = α -class of A to the = α -class of B.

In defining capture-resolving substitution, we will demonstrate a technique that is made possible by the transition from single terms to = α classes of terms. When we have a variable x bound in a term, we can always assume, without loss of generality, that it is distinct from another variable y (since inside our term, we can swap x with any variable from X which is different from y and end up in the same = α -class). By extension, we can also assume that a variable x bound in some term is fresh in some other term.

Definition 1.4.11. Let M and N be terms and x a variable. We define the (capture-resolving) substitution of N for x in M , written as M [x := N ], [START_REF] Blanqui | Termination and confluence of higher-order rewrite systems[END_REF] using the following equations:

(λy. M )[x := N ] = λy. (M [x := N ]) assuming that y ̸ = x and y is fresh for N 20 (M K)[x := N ] = (M [x := N ]) (K[x := N ]) x[x := N ] = N y[x := N ] = y given that x ̸ = y 21 c[x := N ] = c (op M p (λy. M c ))[x := N ] = op (M p [x := N ]) (λy. M c [x := N ]) assuming that y ̸ = x and y is fresh for N (η M )[x := N ] = η (M [x := N ]) ( (op i : M i ) i∈I , η: M η N ′ )[x := N ] = (op i : (M i [x := N ])) i∈I , η: (M η [x := N ]) (N ′ [x := N ]) ( -• M )[x := N ] = -• (M [x := N ]) (C M )[x := N ] = C (M [x := N ])
We are now at a point where we can easily lay down the reduction rules for λ . A reduction rule ξ will be a relation on terms. Most of the time, we will deal with their context closures, [ξ], for which we will also adopt the notation → ξ . We will also use the notation → ξ1,...,ξn for the composition → ξn • . . . • → ξ1 . The reduction relation → of λ is the union of the → ξ relations for every reduction rule ξ. We will also use the symbols ↠ and ↞ ↠ to stand for the reflexive-transitive and reflexive-symmetric-transitive closures of →, respectively. If M ↞ ↠ N , we will also say that M and N are convertible. A term which is not reducible to some other term is said to be in normal form.

We will now go through the reduction rules of λ , presented in Figure 1.4, one by one.

First off, we have the β and η rules. By no coincidence, they are the same rules as the ones found in STLC.

Next we have the three rules that govern the behavior of handlers. We recognize the three different rules as the three different cases in the informal denotational semantics given in Section 1.3.

(λx. M ) N → rule β M [x := N ] λx. M x → rule η M where x / ∈ FV(M ) (op i : M i ) i∈I , η: M η (η N ) → rule η M η N (op i : M i ) i∈I , η: M η (op j N p (λx. N c )) → rule op M j N p (λx. (op i : M i ) i∈I , η: M η N c ) where j ∈ I and x / ∈ FV((M i ) i∈I , M η ) (op i : M i ) i∈I , η: M η (op j N p (λx. N c )) → rule op ′ op j N p (λx. (op i : M i ) i∈I , η: M η N c ) where j / ∈ I and x / ∈ FV((M i ) i∈I , M η ) -• (η M ) → rule -• M C (λx. η M ) → rule C η η (λx. M ) C (λx. op M p (λy. M c )) → rule C op op M p (λy. C (λx. M c ))
where x / ∈ FV(M p )

Figure 1.4: The reduction rules of λ .

• When the expression is just an atom (i.e. η N ), rule η applies the clause M η to the value N contained within.

• When the expression is an operation op j N p (λx. N c (x)) with j ∈ I, we first recursively apply the handler to every child N c (x). We then pass the parameter N p stored in the node along with the cluster of the processed children to the clause M j .

• When the expression is an operation op j N p (λx. N c (x)) but where j / ∈ I, we leave the node as it is and just recurse down on to the subexpressions (effectively using op j as the handler clause for op j ).

By looking at these rules, we also notice that all they do is just traverse the continuations (N c ) and replace η with M η and op i with M i . This justifies thinking of η and the operation symbols as special variables which are bound to a value when being passed through a handler. This substitutability is already hinted at by the types of M η and M i in the typing rule and their correspondence with the typing rules [η] and [op], respectively.

The next rule talks about the cherry operator. It does what we would expect it to do. [START_REF] Brady | Programming and reasoning with algebraic effects and dependent types[END_REF] It expects its argument to always be an atomic algebraic expression, a pure computation, and it extracts the argument that was passed to the η constructor.

Finally, we have the two rules defining the behavior of C. We remind ourselves that the goal of C is to make computations and abstractions commute by pushing λ below operation symbols and η.

• Rule C η treats the base case where the computation that we try to push λ through is a pure computation. In that case, we just reorder the λ binder and the η operator.

• Rule C op deals with the case of the λ meeting an operation symbol. The solution is to push the C operator down through the continuation. The operation C (λx. . . . ) is applied recursively to every child M c (y). However, this strategy is sound only when M p has no free occurrence of x (which would have been bound by the λ in the redex but would become unbound in the contractum). We therefore have a constraint saying that x must not occur free in M p . Unlike the other freshness constraints, this one cannot be fixed by a simple renaming of variables. If this constraint is not met, the C will not be able to reduce.

When talking about the C operator in Section 1.3, we talked about how it applies only to families of computations that share the same internal structure (i.e. functions of x where the internal structure does not depend on x). This is reflected in the reduction rules in two ways:

-Firstly, in order for C op to kick in, the body of the function must have already reduced to something of the form op M p M c . This means that the next operation to be performed has already been determined to be op without needing to wait for the value of x.

-Secondly, the reduction can only proceed if M p does not contain a free occurrence of x. This means that M p is independent of x.

Sums and Products

In the examples throughout this manuscript, we will assume that our calculus has facilities for dealing with sum types and product types (variants and pairs). In this section, we give a brief formal definition of the standard components that will provide these facilities in our calculus.

New Terms

First, we add new expressions into our language:

pair ⟨M, N ⟩ where M and N are expressions The first four concern products. We can construct a pair and then we can project out both of its components. We can also create values of the unit type. The other four implement sums. We can construct two disjoint variants and then we can do case analysis on the results. We can also treat the empty type by handling its zero possible cases.

New Types

We also add new types and type operators: The unit type serves as a unit to the product operator insofar as α × 1, 1 × α and α are isomorphic. It will be used as the input type of operations that do not need to be parameterized and as the output type of operations that do not return any interesting value.

Analogously, the empty type serves as a unit to the sum type since α + 0, 0 + α and α are isomorphic. The empty type is useful as the output type of operations that never return (such as fail : 1 ↣ 0, which terminates a computation, signalling failure).

The standard typing rules of the constructions concerning sums and products are given in Figure 1.5. In the typing rules, we can witness the duality of × and +. There is one introduction rule and two elimination rules for pairs, whereas we have two introduction rules and one elimination rule for variants. We also have an introduction rule for the unit type and an elimination for the empty type.

New Reduction Rules

Now that we know how to correctly write terms with sums and products after having introduced the syntax and the typing rules, we will look at how to simplify and evaluate such terms. We will extend the set of reduction rules in λ with the ones in Figure 1.6. As before, we take the context closure of these rules ξ to get relations → ξ and then we include these relations into our reduction relations → and ↠.

Booleans

The most simple use of a sum type is to serve as a binary Boolean type. Since this comes very handy in examples, we will introduce the typical syntax one expects with Booleans.

We first define the Boolean type 2 to be a type whose value might be either the true element or the false element:

Γ ⊢ M : 0 [empty] Γ ⊢ case M of { } : α Figure 1.5:
The typing rules for sums and products.

π 1 ⟨M, N ⟩ → rule β.× 1 M π 2 ⟨M, N ⟩ → rule β.× 2 N case (inl M ) of {inl x → N l ; inr y → N r } rule β.+ 1 N l [x := M ] case (inr M ) of {inl x → N l ; inr y → N r } rule β.+ 2 N r [y := M ] Figure 1.6:
The reduction rules for sums and products.

Common Combinators

23

True and False are then constructed by injecting ⋆ into 2 using the two different injections:

T = inl ⋆ F = inr ⋆
Finally, we can also simplify the case analysis expression into an if-then-else expression:

if M then N T else N F = case M of {inl x → N T ; inr y → N F }
where x is fresh for N T and y is fresh for N F . This lets us derive the two reduction rules which define the semantics of if-then-else expressions:

if T then N T else N F → if.T N T if F then N T else N F → if.F N F because: if T then N T else N F = case (inl ⋆) of {inl x → N T ; inr y → N F } → β.+1 N T if F then N T else N F = case (inr ⋆) of {inl x → N T ; inr y → N F } → β.+2 N F

Common Combinators

Here we will introduce a collection of useful syntactic shortcuts and combinators for our calculus.

Composing Functions and Computations

First of all, to save some space and write functions in a terse "point-free" style, we introduce the composition operator (known as the B combinator in combinatory logic).

_ • _ : (β → γ) → (α → β) → (α → γ) f • g = λx. f (g x)
We will also "functionalize" our term constructors (i.e. we will write η as a shortcut for (λx. η x)). Our motive in not defining our symbols directly as function constants in the core calculus is due to the proofs of confluence and termination. A complete list of functionalized symbols is given below. [START_REF] Burchardt | Computational semantics[END_REF] Chapter 1. Definitions

η : α → F E (α) π 1 : (α × β) → α η = λx. η x π 1 = λP. π 1 P op : α → (β → F E (γ)) → F E (γ) π 2 : (α × β) → β op = λpc. op p (λx. c x) π 2 = λP. π 2 P (op i : M i ) i∈I , η: M η : F E (γ) → F E ′ (δ) inl : α → (α + β) (op i : M i ) i∈I , η: M η = λx. (op i : M i ) i∈I , η: M η x inl = λx. inl x -• : F ∅ (α) → α inr : β → (α + β) -• = λx. -• x inr = λx. inr x C : (α → F E (β)) → F E (α → β) C = λf. C f
Later on, in Section 3.3, we will see that our F E is a functor which, combined with some other elements, forms a monad, or equivalently, a Kleisli triple. We use a star to denote the extension of a function from values to computations, as in [95], and we use ≫= to denote the bind of a monad, as in Haskell. [START_REF] Cartwright | Extensible denotational language specifications[END_REF] _

* : (α → F E (β)) → (F E (α) → F E (β)) f * = η: f _ ≫= _ : F E (α) → (α → F E (β)) → F E (β) M ≫= N = N * M
Finally, we will define a notation for applying infix operators to arguments wrapped inside computations. Let _ ⊚ _ be an infix operator of type α → β → γ. Then we define the following:

_ ≪⊚ _ : F E (α) → β → F E (γ) X ≪⊚ y = X ≫= (λx. η (x ⊚ y)) _ ⊚≫ _ : α → F E (β) → F E (γ) x ⊚≫ Y = Y ≫= (λy. η (x ⊚ y)) _ ≪⊚≫ _ : F E (α) → F E (β) → F E (γ) X ≪⊚≫ Y = X ≫= (λx. Y ≫= (λy. η (x ⊚ y)))
In particular, we will be using this notation for the function application operator:

_ • _ : (α → β) → α → β f • x = f x
which will yield the following combinators: [START_REF] Cartwright | Extensible denotational language specifications[END_REF] In the types of the operators given below, we use the same effect signature E everywhere. Technically, a more general type could be derived for these terms given our system. However, we will rarely need this extra flexibility and so we stick with these simpler types.

Common Combinators

25 _ ≪• _ : F E (α → β) → α → F E (β) F ≪• x = F ≫= (λf. η (f x)) _ •≫ _ : (α → β) → F E (α) → F E (β) f •≫ X = X ≫= (λx. η (f x)) _ ≪•≫ _ : F E (α → β) → F E (α) → F E (β) F ≪•≫ X = F ≫= (λf. X ≫= (λx. η (f x)))
The first of the three, ≪•, is the inverse function to C. The second, •≫, is the morphism component of the F E functor (which we will demonstrate in Section 3.3). F E is also an applicative functor and the third operator in the list above, ≪•≫, is the operator for application within the functor.

Operations and Handlers

Now we will look at syntactic sugar specific to λ . In 1.6.1, we have seen the bind operator ≫= and other ways of composing computations. Since we now have a practical way to compose computations, we can simplify the way we write effectful operations.

op! = λp. op p (λx. η x)
The exclamation mark partially applies an operation by giving it the trivial continuation η. However, we can still recover op from op! using ≫=:

op! p ≫= k = (λp. op p (λx. η x)) p ≫= k → β op p (λx. η x) ≫= k = k * (op p (λx. η x)) = η: k (op p (λx. η x)) → op ′ op p (λx. η: k (η x)) → η op p (λx. k x)
The exclamation mark streamlines the typing rule for operations, as you can see on the pair of rules below:

op : α ↣ β ∈ E [op] Γ ⊢ op : α → (β → F E (γ)) → F E (γ) op : α ↣ β ∈ E [op!] Γ ⊢ op! : α → F E (β)
We can also see that the ↣ arrow used in effect signatures gives rise to a Kleisli arrow since F E is a monad (as we will see in Subsection 3.3.6).

Handlers

In Section 1.4, we have seen how the reduction rules treat unknown operation symbols: by leaving them intact. With some syntactic sugar, we can extend this behavior to the η operator as well. We will sometimes write a handler and omit giving the η clause. In that case, the η clause is presumed to be just η. [START_REF] Champollion | Back to events: More on the logic of verbal modification[END_REF] Schematically, we can define this piece of new syntax in the following way:

(op i : M i ) i∈I = (op i : M i ) i∈I , η: η
Finally, we will introduce a special syntax for closed handlers [63]. A closed handler is a handler that interprets the entire computation that is given as its input (it must have a clause for every operator that

Examples

We have given a formal definition of λ , our calculus, but we have not shown how to use it to model side effects and what are the benefits. In this chapter, we will present an example problem and as we explore it deeper, we will see emerge some of the properties behind λ .

Contents

Introducing Our Running Example

We will demonstrate our calculus by trying to build a calculator, showing how λ can be used when defining the interpretation of a simple language of arithmetic expressions, similar to the one on which Wadler demonstrates monads in [133]. [START_REF] Charlow | On the semantics of exceptional scope[END_REF] Given some arithmetic expression, we would like to reduce it to a simple number.  ( 1) ( ( 2) ( 4)) → 9

In the above, expressions are formed using the constructors ,  and  which stand for sums, products and literals, respectively. Expressions in our calculator have the type exp, the types of the constructors (formation rules) are given below:

Raising the Type of exp

Now the cases when x/y is and is not defined are clearly delimited. [START_REF] Hayes | Montague's semantic theory and transformational syntax a dissertation[END_REF] Nevertheless, we just made ourselves a new problem. The result of a division is something of type N + 1 and so in our interpretation, exp will correspond to N + 1. This is in line with our intuition that arithmetic expressions which contain division can sometimes be undefined. However, the implications of having exp = N + 1 begin to sting when we consider the cases of  and . 33

exp = N + 1  = λXY. case X of {inl x → case Y of {inl y → x/y; inr _ → inr ⋆}; inr _ → inr ⋆}  = λXY. case X of {inl x → case Y of {inl y → inl (x + y); inr _ → inr ⋆}; inr _ → inr ⋆}  = λXY. case X of {inl x → case Y of {inl y → inl (x × y); inr _ → inr ⋆}; inr _ → inr ⋆}  = λx. inl x
We now have to inspect the results of both of the operands and proceed with the calculation only if both of the operands successfully yield a natural number. [START_REF] Govert | Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the church-rosser theorem[END_REF] In ,  and , we also have to wrap the result in inl in order to go from N to N + 1. In , we do not wrap the result using inl since division already produces a value of type N + 1. All this seems a heavy price to pay just to include division.

Refactoring with Monads

We can make this solution look a little bit better. We can introduce a function on types and a pair of combinators that will allow us to be a little less repetitive.

T ⊥ (α) = α + 1 η ⊥ : α → T ⊥ (α) η ⊥ = inl (≫= ⊥ ) : T ⊥ (α) → (α → T ⊥ (β)) → T ⊥ (β) (≫= ⊥ ) = λXk. case X of {inl x → k x; inr _ → inr ⋆}
With these in our hands, we can now straighten out our interpretation.

exp = T ⊥ (N)  = λXY. X ≫= ⊥ (λx. Y ≫= ⊥ (λy. x/y))  = λXY. X ≫= ⊥ (λx. Y ≫= ⊥ (λy. η ⊥ (x + y)))  = λXY. X ≫= ⊥ (λx. Y ≫= ⊥ (λy. η ⊥ (x × y)))  = λx. η ⊥ x
This pattern that we uncovered in the type N + 1 and the terms defining , ,  and  is not incidental. The triple ⟨T ⊥ , η ⊥ , ≫= ⊥ ⟩ forms a monad. This formulation in terms of monadic operations will allow us to transition more easily into our proposed solution since, as we will show in 3.3.6, ⟨F E , η, ≫=⟩ also forms a monad. [START_REF] Hayes | Montague's semantic theory and transformational syntax a dissertation[END_REF] Realizing that x/y is not defined for y = 0 and then changing the type and behavior of the underlying division operator is very much like semanticists taking into account that expressions such as the King of France need not have a reference and then changing the underlying model. [START_REF] Danvy | A functional abstraction of typed contexts[END_REF] As a convention, we use _ as a variable name for variables whose values are never used. [START_REF] Govert | Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the church-rosser theorem[END_REF] If you are unfamiliar with the notation used in the terms above, consult Section 1.5, where we introduced sums and products into our calculus.

Interpreting Expressions as Computations

We will now explore an alternative solution which takes advantage of the F-types in λ . We will interpret expressions as computations of natural numbers, exp = F E (N). Computations can have the ability to fail by using the operation fail : 1 ↣ 0. The input type 1 means that there is only one way to fail (i.e. fail does not distinguish failure states) and the output type 0 means that there is no continuation (formally there is a dummy continuation that accepts the impossible type 0). There is a natural way to generalize this approach by using error : χ ↣ 0 instead. Computations can now terminate by throwing exceptions of type χ, allowing us to distinguish failure states. To identify the division-by-zero failure state, we will introduce DivisionByZero : χ. A computation that uses the error operation to throw a division-by-zero exception would look like the following:

• 0 : F {error:χ↣0} (α) • 0 = error DivisionByZero (λo. case o of { })
The continuation uses the [empty] rule to turn the o of type 0 into something of type F E (α).

exp = F {error:χ↣0} (N)  = λXY. X ≫= (λx. Y ≫= (λy. case (x/y) of {inl z → η z; inr _ → • 0 }))  = λXY. X ≫= (λx. Y ≫= (λy. η (x + y)))  = λXY. X ≫= (λx. Y ≫= (λy. η (x × y)))  = λx. η x
Let us compare this with the last set of definitions:

• We replaced the ⟨T ⊥ , η ⊥ , ≫= ⊥ ⟩ monad with the ⟨ F {error:χ↣0} , η, ≫= ⟩ monad.

• Since the type of x/y is not the same as the type of our interpretations, we need to translate from the type N + 1 to the type F {error:χ↣0} (N) by case analysis.

The advantage to using the F E monad instead of the T ⊥ monad is that the F E can be extended to handle other kinds of effects besides exceptions whereas the T ⊥ monad would need to be replaced by a different one. We will see an example of this later in 2.3. For now, we still have something more to explore regarding errors.

Handling Errors

We can now use division in our small calculator language. However, division can make the evaluation of an expression fail and yield no useful result. We could thus ask for a way to speculatively evaluate a subexpression and if it fails, recover by providing some default value and carry on evaluating the rest of the expression.

We add a new construction into our language:

 : exp → exp → exp
Its intended meaning is to return the value of its second argument. However, if the second argument fails to evaluate, the value of the first argument should be used instead.

 ( 42) ( ( 1) ( 0)) → η 42

Our task now is to give a formal semantics to .  = λXY. error: (λek. X) Y Instead of passing Y through the ≫= operator, which basically says to do whatever Y would do (i.e. fail whenever Y fails), we apply a handler to Y . [START_REF] De | Towards abstract categorial grammars[END_REF] This handler is very simple, it replaces any failed computation with the computation X (the backup computation that should yield the default value). It behaves like the exception handlers of common programming languages, whenever the computation Y would throw an error, we handle it by running computation X instead.

Examples with Errors

We now have enough interesting material to play around with and see if (and why) it really works as it should. We will take an expression large enough to contain all the features which we added and we will evaluate it piece by piece.

 ( 5) ( ( 0) ( ( 3) ( ( 2) ( 0)))) Let's start with  ( 2) ( 0).  ( 2) ( 0) =  (η 2) (η 0) (1)
= (λXY. X ≫= (λx. Y ≫= (λy. case (x/y) of {inl z → η z; inr _ → • 0 }))) (η 2) (η 0) (2) → β,β (η 2) ≫= (λx. (η 0) ≫= (λy. case (x/y) of {inl z → η z; inr _ → • 0 })) (3)
= (λx. (η 0) ≫= (λy. case (x/y) of {inl z → η z; inr _ → • 0 })) * (η 2) (4) = η: (λx. (η 0) ≫= (λy. case (x/y) of {inl z → η z; inr _ → • 0 })) (η 2) (5)
→ η (λx. (η 0) ≫= (λy. case

(x/y) of {inl z → η z; inr _ → • 0 })) 2 (6)
→ β (η 0) ≫= (λy. case (2/y) of {inl z → η z; inr _ → • 0 }) (7)
→ ... (λy. case (2/y) of {inl z → η z; inr _ → • 0 }) 0 (8)
→ β case (2/0) of {inl z → η z; inr _ → • 0 } (9)
→ / case (inr ⋆) of {inl z → η z; inr _ → • 0 } (10)
→ β.+2 • 0 (11)
The reductions state which rule was used to perform the step. The equality on line 2 is due to our interpretation of . Those on lines 4 and 5 come from the definitions of ≫= and * in 1.6.1. The step on line 8 is just a repeat of the steps on lines 4 to 6. This sequence of steps will be quite common and we will from now on refer to it as the reduction rule η.≫=. [START_REF] De | Type raising, continuations, and classical logic[END_REF] The result of this first elaboration was not surprising: dividing 2 by 0 throws a DivisionByZero exception. We will now try to see what happens when this faulty expression appears within another expression.

32

Chapter 2. Examples

 ( 3) • 0 =  (η 3) • 0 (1) = (λXY. X ≫= (λx. Y ≫= (λy. η (x × y)))) (η 3) • 0 (2) → β,β (η 3) ≫= (λx. • 0 ≫= (λy. η (x × y))) (3)
→ η.≫= (λx. • 0 ≫= (λy. η (x × y))) 3 (4)
→ β • 0 ≫= (λy. η (3 × y)) (5)
= (error DivisionByZero (λo. case o of { })) ≫= (λy. η (3 × y)) (6)
= (λy. η (3 × y)) * (error DivisionByZero (λo. case o of { })) (7) = η: (λy. η (3 × y)) (error DivisionByZero (λo. case o of { })) (8)
→ op ′ error DivisionByZero (λo. η: (λy. η (3 × y)) (case o of { })) (9)
≃ • 0 ( 10
)
Line 2 is due to our interpretation of . Line 4 is due to the η.≫= rule that we have demonstrated in the last example. Lines 6, 7 and 8 expand the definitions of • 0 , ≫= and * respectively. On line 10, we equate the term with • 0 . The terms differ in the continuation but since the continuation can never be called, [START_REF] De | Tree-adjoining grammars as abstract categorial grammars[END_REF] we can consider them equal.

We have seen the DivisionByZero exception propagate. Now let's see what happens when it hits a  construction.

 ( 0) • 0 =  (η 0) • 0 (1)
= (λXY. error:

(λek. X) Y ) (η 0) • 0 (2) → β,β error: (λek. η 0) • 0 (3) = error: (λek. η 0) (error DivisionByZero (λo. case o of { })) (4)
→ op (λek. η 0) DivisionByZero (λo. error:

(λek. η 0) (case o of { })) (5)
→ β,β η 0 ( 6
)
Line 2 is our interpretation of . Line 4 is the definition of • 0 . We see that since the embedded expression failed to evaluate (its denotation was • 0 ), we have evaluated the literal 0 instead. We now have an actual number again and we can try feeding it into another operation. [START_REF] De | Tree-adjoining grammars as abstract categorial grammars[END_REF] Technical aside: To be precise, we should define • 0 to be a class of terms of the shape error DivisionByZero (λo. M ) for any term M . The only operations we will ever perform on • 0 in these examples will be congruent with the equivalence relation of our calculus refined by adding equalities between terms of the shape error DivisionByZero (λo. M ). Therefore, so long as we end up removing the • 0 terms from our result, we can treat them as equivalent during our calculations.

 ( 5) (η 0) =  (η 5) (η 0)

= (λXY. X ≫= (λx. Y ≫= (λy. η (x + y)))) (η 5) (η 0) (1)
→ β,β (η 5) ≫= (λx. (η 0) ≫= (λy. η (x + y)))

→ η.≫= (λx. (η 0) ≫= (λy. η (x + y))) 5 (3)
→ β (η 0) ≫= (λy. η (5 + y))

→ η.≫= (λy. η (5 + y)) 0 (6)

→ β η (5 + 0) (7)
→ + η 5 ( 8
)
Line 2 is our interpretation of . The others are reductions of the kind we have seen before. Finally, we have seen the simplest case, when an operator just reaches into the results of both operands using → η.≫= and carries out its operation. This also concludes our evaluation of the expression we have presented at the beginning of this subsection. We can therefore now conclude that:

 ( 5) ( ( 0) ( ( 3) ( ( 2) ( 0)))) → η 5

Enriching the Context with Variables

Sometimes, when writing down arithmetic expressions, it becomes useful to introduce variables for intermediate expressions and then build up the final result using those. Let's try and add such a facility to our calculator.  : var → exp → exp → exp  : var → exp x, ȳ, z, . . . : var  binds a variable to the result of the first expression; this variable stays available during the evaluation of the second expression.  then lets us use the variable in place of an expression. We also introduce terms for the different variables that can be used in our calculator. They look the same as the variables in λ but they have a bar on top.

Here is a term that uses the new constructions:

 x ( ( 2) ( 3)) ( ȳ ( ( x) ( x)) ( ( ȳ) ( 2))) → η 50
In order to give a semantics to  and , we will augment the set of operations in the computations we use to interpret the expressions. We want computations to be able to ask for the values of variables and so we will introduce get : var ↣ N. In our new interpretation, we will have exp = F {error:χ↣0,get:var↣N} (N). Though it might seem that we are changing our domain of interpretation and will thus need to redo our existing interpretations, it is actually not the case. The type that we associated with exp before could have been more precisely written as F {error:χ↣0}⊎E (N), where E is a free variable ranging over effect signatures. What we are doing is simply specifying E = {get : var ↣ N} ⊎ E ′ , where

E ′ is again free.  = λvXY. X ≫= (λx. get: (λuk. if u = v then (k x) else (get u k)) Y )  = get!
In the implementation above, we also rely on the presence of an equality predicate on the var type: 38

(=) : var → var → 2
And that is all we need. We can put these two combinators side-by-side with the existing ones like  and  and we will have a semantics for a calculator with exceptions and variables.

Example with Variables

To get some practice with λ , we will evaluate a simple expression with multiple variables, step by step.

 x ( 1) ( ȳ ( 2) ( ( x) ( ȳ)))
Let us start off with the innermost expression, the sum of x and ȳ.

 ( x) ( ȳ) =  (get! x) (get! ȳ) (1) = (λXY. X ≫= (λx. Y ≫= (λy. η (x + y)))) (get! x) (get! ȳ) (2)
→ β,β (get! x) ≫= (λx. (get! ȳ) ≫= (λy. η (x + y))) (3) = ((λp. get p (λx. η x)) x) ≫= (λx. (get! ȳ) ≫= (λy. η (x + y))) (4)
→ β (get x (λx. η x)) ≫= (λx. (get! ȳ) ≫= (λy. η (x + y))) (5)
= η: (λx. (get! ȳ) ≫= (λy. η (x + y))) (get x (λx. η x)) (6)
→ op ′ get x (λx. η: (λx. (get! ȳ) ≫= (λy. η (x + y))) (η x)) (7)
→ η get x (λx. (λx. (get! ȳ) ≫= (λy. η (x + y))) x) (8)
→ β get x (λx. (get! ȳ) ≫= (λy. η (x + y))) (9)
→ ... get x (λx. get ȳ (λy. η (x + y)))

The first three lines are the usual. First, we expand the definitions of the operands (the  operator). Then we do the same for the operation  and we β reduce.

On line 4, we substitute get! with the definition of the exclamation mark that we provided in 1.6.2. Similarly, on line 6, we expand the definition of ≫=. [START_REF] De | On logical relations and conservativity[END_REF] If you compare line 3 and line 9 (the second to last line), you will notice that they are practically identical. The (get! x) ≫= (λx. . . .) on line 3 has been replaced with get x (λx. . . .). This is a derivable rule in λ , which we call op!.≫=. [START_REF] De | A note on intensionalization[END_REF] On the last line, we simply repeat the last 6 steps (which we now packaged into the op!.≫= rule) for get! ȳ.

We have our result, a computation that asks for the values of the variables x and ȳ to compute their sum. Now we will compute the value of  ȳ ( 2). [START_REF] De | Towards a montagovian account of dynamics[END_REF] 2 is the Boolean type that we have defined in Section 1.5 as 1 + 1. [START_REF] De | On logical relations and conservativity[END_REF] ≫= is defined in terms of * , which is itself defined in terms of . Here, we expand both in one go, i.e. (x ≫= f ) = ( η: f x) [START_REF] De | A note on intensionalization[END_REF] In Subsection 3.1.2, we will derive a similar, but more general, rule called op.≫=, which will cover the steps from line 5 to line 8.

 ȳ ( 2) =  ȳ (η 2) (1) = (λvXY. X ≫= (λx. get: (λuk. if u = v then (k x) else (get u k)) Y )) ȳ (η 2) (2)
→ β,β λY. (η 2) ≫= (λx. get: (λuk. if u = ȳ then (k x) else (get u k)) Y ) (3)
→ η.≫= λY. (λx. get: (λuk. if u = ȳ then (k x) else (get u k)) Y ) 2 (4)
→ β λY. get: (λuk. if u = ȳ then (k 2) else (get u k)) Y (5)
→ η get: (λuk. if u = ȳ then (k 2) else (get u k)) (6)
Lines 1 and 2 are our interpretations of  and  and the rest are applications of rules we have seen before. We find out that the semantic action of  ȳ ( 2) is a handler. This handler is only interested in get operations that act on the variable ȳ. It interprets such operations by returning the value 2, otherwise it leaves them untouched.

We will now apply this handler to the meaning of  ( x) ( ȳ) to get the meaning of  ȳ ( 2) ( ( x) ( ȳ)).

 ȳ ( 2) ( ( x) ( ȳ))

(1)

=  ȳ ( 2) (get x (λx. get ȳ (λy. η (x + y)))) (2)
= get:

(λuk. if u = ȳ then (k 2) else (get u k)) (get x (λx. get ȳ (λy. η (x + y)))) (3)
→ op (λuk. if u = ȳ then (k 2) else (get u k)) x (λx.  ȳ ( 2) (get ȳ (λy. η (x + y)))) (4)
→ β (λk. if x = ȳ then (k 2) else (get x k)) (λx.  ȳ ( 2) (get ȳ (λy. η (x + y)))) (5)
→ = (λk. if F then (k 2) else (get x k)) (λx.  ȳ ( 2) (get ȳ (λy. η (x + y)))) (6)
→ if.F (λk. (get x k)) (λx.  ȳ ( 2) (get ȳ (λy. η (x + y)))) (7)
→ β get x (λx.  ȳ ( 2) (get ȳ (λy. η (x + y)))) (8)
= get x (λx. get:

(λuk. if u = ȳ then (k 2) else (get u k)) (get ȳ (λy. η (x + y)))) (9)
→ op get x (λx. ((λuk. if u = ȳ then (k 2) else (get u k)) ȳ (λy.  ȳ ( 2) (η (x + y))))) (10)
→ β get x (λx. ((λk. if ȳ = ȳ then (k 2) else (get ȳ k)) (λy.  ȳ ( 2) (η (x + y))))) (11)
→ = get x (λx. ((λk. if T then (k 2) else (get ȳ k)) (λy.  ȳ ( 2) (η (x + y))))) (12)
→ if.T get x (λx. ((λk. k 2) (λy.  ȳ ( 2) (η (x + y))))) (13)
→ β get x (λx. (λy.  ȳ ( 2) (η (x + y))) 2) (14)
→ β get x (λx.  ȳ ( 2) (η (x + 2))) (15)
= get x (λx. get:

(λuk. if u = ȳ then (k 2) else (get u k)) (η (x + 2))) (16)
→ η get x (λx. η (x + 2)) (17)
This one is a bit more complicated and so we will go through it line by line:

Line 2 (=) We replace the expression  ( x) ( ȳ) with its denotation that we computed earlier.

Line 3 (=)

We do the same for the construction  ȳ ( 2).

Line 4 (→ op )

The let-binder is a handler with a clause for get and its argument is a computation that performs get. This means we do two things: we replace get with the clause (λuk. . . .) from the handler and we move the handler inside the continuation. In order to save space, we contract the handler back to  ȳ ( 2).

Line 5 (β)

Here we apply the handler clause to the operation's argument, the variable x. We do not do the same for the continuation argument k since we would have to copy it twice and we can avoid that by reducing the conditional expression first.

Line 6 (=) Since x and ȳ are different variables, we expect the equality predicate to return false (F).

Line 7 (if.F) Since the condition evaluated to F, we choose the second branch of the conditional. The reduction rule used here was derived in Subsection 1.5.4.

Line 8 (β)

We have simplified the handler clause and so we are ready to substitute in the continuation. Remark the similarity between this line and line 2. The only difference is the position of the  ȳ ( 2) handler. It has moved from the first get down to the second get.

Line 9 (=)

We will proceed as we did from line 3 onward. We expand  ȳ ( 2) to reveal the handler.

Line 10 ( op )

We have another get computation and so we pull out the handler clause for get. We contract the handler back into  ȳ ( 2) and move it down, applying it to the next step of the computation in the same way as was described at line 4.

Line 11 (β)

We pass the variable ȳ into the handler clause so we can decide the condition.

Line 12 (=) This time, we are comparing a variable to itself and so the equality predicate will yield true (T).

Line 13 (if.T) Since the condition is true, we choose the first branch of the conditional.

Line 14 (β)

Having simplified the handler clause, we can pass in the continuation so that we can supply it with the value of the variable ȳ that it was looking for.

Line 15 (β)

We pass 2 to the continuation.

Line 16 (=) Now we will use the handler one last time so we reveal it first by expanding  ȳ ( 2).

Line 17 ( η )

The handler has no clause for η. In 1.6.2, we have declared that this is just a syntactic shortcut for the handler having a default clause η: η. Applying the η rule has two effects: we replace η with its handler clause, η, and we discard the handler since there is no continuation.

We have started with get x (λx. get ȳ (λy. η (x + y))) as the denotation of  ( x) ( ȳ). By applying the denotation of  ȳ ( 2), we have interpreted away the get ȳ request by providing the value 2 as the response, leaving us with get x (λx. η (x + 2)). We will resolve the variable x by analogy.

 x ( 1) → ... get: (λuk. if u = x then (k 1) else (get u k))
This computation goes down the same way as the one for  x ( 1), only the number and the variable name are different.  x ( 1) ( ȳ ( 2) ( ( x) ( ȳ))) =  x ( 1) (get x (λx. η (x + 2)))

→ ... η (1 + 2) → + η 3
We can perform the reduction from the first line to the second line by repeating the exact same steps as we did from line 8 to line 17 when simplifying  ȳ ( 2) (get ȳ (λy. η (x + y))).

Finally, we can conclude that according to our interpretations, the value of the expression we started off with is 3. In other words, the following holds:

 x ( 1) ( ȳ ( 2) ( ( x) ( ȳ))) → η 3

Treating Variables without Computations

Before we proceed onto the next chapter, let us compare the calculator semantics that we have developed so far with an alternative that does not rely on the computation abstraction.

As a reminder, this is our calculator semantics from 2.2.1, along with a semantics for .

exp = N + 1  = λXY. case X of {inl x → case Y of {inl y → x/y; inr _ → inr ⋆}; inr _ → inr ⋆}  = λXY. case X of {inl x → case Y of {inl y → inl y; inr _ → inl x}; inr _ → inr ⋆}  = λXY. case X of {inl x → case Y of {inl y → inl (x + y); inr _ → inr ⋆}; inr _ → inr ⋆}  = λXY. case X of {inl x → case Y of {inl y → inl (x × y); inr _ → inr ⋆}; inr _ → inr ⋆}  = λx. inl x
What denotation should we assign to  x? It does not correspond to any particular natural number nor is it an expression that should always fail. We can find an answer to our question by expanding the domain from N + 1 to γ → (N + 1) where γ = var → (N + 1) is the type of environments. 41 Since we needed to expand the type exp into γ → N + 1, we need to make appropriate changes to the previous denotations. When producing values of type exp, we now abstract over an argument e of type γ. When consuming values of type exp, we apply to them an environment of type γ to get a value of the old type N + 1.

exp = γ → N + 1 γ = var → N + 1  = λvXY e.
In the rule for , we just lookup the value of the variable in the environment. If the environment does not contain a value for this variable, it returns inr ⋆ of type N + 1. In that case,  returns the same to indicate that the expression has no reference. In , we evaluate X in the current environment e and if it has a value, we also evaluate Y . However, Y itself is evaluated in an environment in which v is bound to x, the value of X.

We can now compare this to the semantics that we have arrived at using effects and handlers. exp = F {error:χ↣0,get:var↣N} (N)  = λvXY. X ≫= (λx. get:

(λuk. if u = v then (k x) else (get u k)) Y )  = get!  = λXY. X ≫= (λx. Y ≫= (λy. case (x/y) of {inl z → η z; inr _ → • 0 }))  = λXY. error: (λek. X) Y  = λXY. X ≫= (λx. Y ≫= (λy. η (x + y)))  = λXY. X ≫= (λx. Y ≫= (λy. η (x × y)))  = λx. η x
We notice that get is used in  and  but it is not mentioned in other parts of the fragment. error is used in  (through • 0 ) and in  and again it is absent in the rest of the fragment. Compare this with the approach that models exp as γ → N + 1. In all of the entries, we abstract over a variable of type γ for the current environment and we explicitly pass it around. We also do explicit case analysis on all intermediate results and we wrap all our results in inl. Furthermore, changing the type exp to accommodate  and  forced us to change the definitions of , , ,  and  (i.e. all the other constructions in our fragment).

We could solve some of these problems by using the same technique we have seen in 2.2.2. We can find a monad whose type constructor is T (α) = γ → α + 1, whose unit is η = (λxe. inl x) and whose bind simultaneously takes care of passing around the environment and performing case analysis on intermediate results. However, we would still need to rewrite the existing parts of the semantics to use the new monad.

Summary

In this chapter, we have hoped to convey two things:

• Some sense of familiarity with our calculus.

We have performed long reduction chains which illustrated a large part of the reduction rules and syntax introduced in Chapter 1. The goal of that was to build up our intuition of how terms written in λ actually look like and how to use them to write computations.

• A glimpse of the methodology we would like to adopt.

As a running example in this chapter, we have studied a simple formal language and gave it a compositional semantics. In the process of doing that, we have seen some advantages of using computations as opposed to using simpler terms. Notably the fact that we could extend the fragment with new constructions that demonstrate new semantic phenomena, such as errors or variables, without having to rewrite existing denotations. One of the principal motivations of this thesis is to apply this technique to the problem of natural language semantics and verify whether we can enjoy the same properties. these syntactic extensions during the reduction of a term is a tedious process and we have introduced some shortcuts to allow us to proceed faster and at a higher level of abstraction (e.g. the η.≫= rule). In this section, we will give typing rules and reduction rules to these new constructions and prove their correctness.

Function Composition (•)

The first piece of syntactic sugar we have introduced was an infix symbol for function composition.

f • g = λx. f (g x)
In order to type terms containing this symbol, it will be useful to have a typing rule. Proposition 3.1.1. The following typing rule is derivable in λ :

Γ ⊢ M : β → γ Γ ⊢ N : α → β [•] Γ ⊢ M • N : α → γ Proof. Since M • N = λx. M (N x)
, we can prove the validity of this rule with the typing rule below:

Γ, x : α ⊢ M : β → γ Γ, x : α ⊢ N : α → β Γ, x : α ⊢ x : α [app] Γ, x : α ⊢ N x : β [app] Γ, x : α ⊢ M (N x) : γ [abs] Γ ⊢ λx. M (N x) : α → γ
x is presumed to be fresh for M and N and so we can equate Γ, x : α ⊢ M : β → γ with Γ ⊢ M : β → γ and the same for N .

The result of function composition is another function and functions can be applied to arguments. We can derive a reduction rule for this kind of function. Proposition 3.1.2. The following reduction is derivable in λ :

(M 1 • M 2 ) N → • M 1 (M 2 N ) Proof. (M 1 • M 2 ) N = (λx. M 1 (M 2 x)) N → β M 1 (M 2 N )

Monadic Bind (≫=)

As a reminder, we give the definition of ≫= from 1.6.1.

M ≫= N = N * M = η: N M
First, we will prove the correct typing for ≫=.

Proposition 3.1.3. The following typing rule is derivable in λ :

Γ ⊢ M : F E (α) Γ ⊢ N : α → F E (β) [≫=] Γ ⊢ M ≫= N : F E (β)
long as we abstain from using the partial function C. The latter is known as termination and its proof is more involved, so we will delay it until 3.5.

For both of these properties to hold, it will be essential to prove that a typed term stays typed after performing a reduction. This will be the object of the next subsection.

Subject Reduction

We now turn our attention to the subject reduction property. We can summarize subject reduction with the slogan "reduction preserves types". The rest of this section will consider a formal proof of this property for λ , but before we begin, we present a small lemma.

Lemma 3.2.1. Substitution and types

Whenever we have Γ, x : α ⊢ M : τ and Γ ⊢ N : α, we also have Γ ⊢ M [x := N ] : τ (i.e. we can substitute in M while preserving the type).

Proof. The proof is carried out by induction on the structure of M (or rather the structure of the type derivation Γ ⊢ M : τ ).

• M = y • All the other cases end up being trivial. We follow the definition of substitution (Definition 1.4.11) which just applies substitution to all of the subterms. For every such subterm, we make appeal to the induction hypothesis and construct the new typing derivation.

-If y = x,

Property 3.2.2. Subject reduction

If Γ ⊢ M : τ and M → N , then Γ ⊢ N : τ .

Proof. We prove this by induction on the reduction rule used in M → N .

• M → β N It must be the case that M = (λx. M ′ ) M ′′ and N = M ′ [x := M ′′ ].
Since, Γ ⊢ M : τ , we must have the following typing derivation:

Γ, x : α ⊢ M ′ : τ [abs] Γ ⊢ λx. M ′ : α → τ Γ ⊢ M ′′ : α [app] Γ ⊢ (λx. M ′ ) M ′′ : τ We apply Lemma 3.2.1 to Γ, x : α ⊢ M ′ : τ and Γ ⊢ M ′′ : α to get a typing derivation for Γ ⊢ M ′ [x := M ′′ ] : τ . • M → η N
We have M = λx. M ′ x with x fresh for M ′ , N = M ′ and τ = τ 1 → τ 2 . Since Γ ⊢ M : τ , we have the following:

Γ, x : τ 1 ⊢ M ′ : τ 1 → τ 2 Γ, x : τ 1 ⊢ x : τ 1 [app] Γ, x : τ 1 ⊢ M ′ x : τ 2 [abs] Γ ⊢ λx. M ′ x : τ 1 → τ 2
From the types of M p , M c and M j , we can calculate the type of our redex, M j M p (λx. (op i :

M i ) i∈I , η: M η M c ). Γ ⊢ M j : α j → (β j → F E ′ (δ)) → F E ′ (δ) Γ ⊢ M p : α j [app] Γ ⊢ M j M p : (β j → F E ′ (δ)) → F E ′ (δ) Γ, x : β j ⊢ M c : F E (γ) … [ ] Γ, x : β j ⊢ (op i : M i ) i∈I , η: M η M c : F E ′ (δ) [abs] Γ ⊢ λx. (op i : M i ) i∈I , η: M η M c : β j → F E ′ (δ) [app] Γ ⊢ M j M p (λx. (op i : M i ) i∈I , η: M η M c ) : F E ′ (δ) • M → op ′ N We have M = (op i : M i ) i∈I , η: M η (op M p (λx. M c )), N = op M p (λx. (op i : M i ) i∈I , η: M η M c ) and τ = F E ′ (δ). Γ ⊢ M p : α Γ, x : β ⊢ M c : F E (γ) op : α ↣ β ∈ E [op] Γ ⊢ op M p (λx. M c ) : F E (γ) op : α ↣ β ∈ E ′ … [ ] Γ ⊢ (op i : M i ) i∈I , η: M η (op M p (λx. M c )) : F E ′ (δ)
From the inferred judgments, we can build a typing derivation for the redex.

Γ ⊢ M p : α Γ, x : β ⊢ M c : F E (γ) … [ ] Γ, x : β ⊢ (op i : M i ) i∈I , η: M η M c : F E ′ (δ) op : α ↣ β ∈ E ′ [op] Γ ⊢ op M p (λx. (op i : M i ) i∈I , η: M η M c ) : F E ′ (δ) • M → -• N In this case, M = -• (η M ′ ) and N = M ′ . Γ ⊢ M ′ : τ [η] Γ ⊢ η M ′ : F ∅ (τ ) [ -• ] Γ ⊢ -• (η M ′ ) : τ
We immediately get Γ ⊢ M ′ : τ , which is the sought after typing derivation of the redex.

• M → Cη N M = C (λx. η M ), N = η (λx. M ) and τ = F E (γ → δ). Γ, x : γ ⊢ M : δ [η] Γ, x : γ ⊢ η M : F E (δ) [abs] Γ ⊢ λx. η M : γ → F E (δ) [C] Γ ⊢ C (λx. η M ) : F E (γ → δ)
From these judgments, we build a type for the redex.

Γ, x : γ ⊢ M : δ [abs] Γ ⊢ λx. M : γ → δ [η] Γ ⊢ η (λx. M ) : F E (γ → δ) • M → Cop N M = C (λx. op M p (λy. M c )), N = op M p (λy. C (λx. M c )) and τ = F E (γ → δ). Γ, x : γ ⊢ M p : α Γ, x : γ, y : β ⊢ M c : F E (δ) op : α ↣ β ∈ E [op] Γ, x : γ ⊢ op M p (λy. M c ) : F E (δ) [abs] Γ ⊢ λx. op M p (λy. M c ) : γ → F E (δ) [C] Γ ⊢ C (λx. op M p (λy. M c )) : F E (γ → δ)
With the judgments above, we build the derivation below.

Γ ⊢ M p : α Γ, y : β, x : γ ⊢ M c : F E (δ) [abs] Γ, y : β ⊢ λx. M c : γ → F E (δ) [C] Γ, y : β ⊢ C (λx. M c ) : F E (γ → δ) op : α ↣ β ∈ E [op] Γ ⊢ op M p (λy. C (λx. M c )) : F E (γ → δ)
In the above we get Γ ⊢ M p : α from Γ, x : γ ⊢ M p : α and the rule's condition that x / ∈ FV(M p ).

•

C[M ′ ] → C[N ′ ]
The reduction relation of λ is defined as the context closure of the individual reduction rules. We have covered the rules themselves, we now address the context closure. By induction hypothesis, we know that the reduction from M ′ → N ′ preserves types, i.e. for any ∆ and α such that ∆ ⊢ M ′ : α, we have ∆ ⊢ N ′ : α.

We observe that the typing rules of λ (Figure 1.1) are compositional, meaning that the type of a term depends only on the types of its subterms, not on their syntactic form. We can check this easily by looking at the premises of all of the typing rules. For every immediate subterm T , there is a premise ∆ ⊢ T : α where T is a metavariable. We can therefore replace T and its typing derivation by some other T ′ with ∆ ⊢ T ′ : α.

Since the typing rules of λ are compositional, we can replace the

∆ ⊢ M ′ : α in Γ ⊢ C[M ′ ] : τ by ∆ ⊢ N ′ : α and get Γ ⊢ C[N ′ ] : τ .
We have proven subject reduction for core λ . The syntax, semantics and types that we have introduced for sums and products are standard. Their proofs of subject reduction carry over into our setting as well.

Progress

Progress means that typed terms are never stuck. Among the terms of λ , we will have to identify terms which are acceptable stopping points for reduction. Progress will mean that if a term is not in one of these acceptable positions, then there must be a way to continue reducing. The term we will use for these acceptable results is value. Definition 3.2.3. A λ term is a value if it can be generated by the following grammar:

V ::= λx. M | op V (λx. M ) | η V
where M ranges over λ terms.

The above definition reflects the intuition that λ consists of functions and computations, where functions are built using λ and computations using op and η. The other syntactic constructions (application, , -• and C) all have rules which are supposed to eventually replace them with other terms. As with subject reduction, before we proceed to the main property, we will start with a small lemma.

Lemma 3.2.4. Value classification

Let V be a closed well-typed value (i.e. ∅ ⊢ V : τ ). Then the following hold:

• if τ = α → β, then V = λx. M • if τ = F E (α), then either V = op V p (λx. M c ) or V = η V ′ Proof. • Assume τ = α → β. If V = op V p (λx. M c ) or V = η V ′ , then τ must be a computation type F E (γ),
which is a contradiction. The only remaining possibility is therefore V = λx. M .

• Assume τ = F E (α). If V = λx. M , then τ must be a function type β → γ, which is a contradiction. The only remaining possibilities are therefore

V = op V p (λx. M c ) or V = η V ′ .
Property 3.2.5. Progress Every closed well-typed term M from λ without C and constants [START_REF] Felleisen | Semantics engineering with PLT Redex[END_REF] is either a value or is reducible to some other term.

Proof. We will proceed by induction on M .

• M = λx. M ′ Then M is already a value.

• M = x Impossible, since M must be a closed term.

• M = M 1 M 2
By induction hypothesis, M 1 and M 2 are either values or reducible terms. If either one is reducible, then our term is reducible as well and we are done. If neither is reducible, then they are both values. Since M is a closed well-typed term (i.e. ∅ ⊢ M : τ ), then ⊢ M 1 : α → τ for some α. Thanks to Lemma 3.2.4, we have that M 1 = λx. M ′ 1 . This means that M = (λx. M ′ 1 ) M 2 and M is therefore reducible with β.

• M = op M p (λx. M c )
By induction hypothesis, M p is either reducible or a value. If M p is reducible, then so is M . If it is a value, then so is M as well.

• M = η N The same argument as for op. By induction hypothesis N is reducible or a value and therefore the same holds for M .

• M = (op i : M i ) i∈I , η: M η N
By induction hypothesis, N is either a value or it is itself reducible. If it is reducible, then so is M . If it is not, then it must be a (closed) value. The type of N is a computation type F E (α) and so by Lemma 3.2.4, it must either be op

V p (λx. M c ) or η V . If N = op V p (λx. M c ), then (op i : M i ) i∈I , η: M η (op V p (λx. M c )
) is reducible by op or op ′ (depending on whether or not op ∈ {op i } i∈I ). Otherwise, if N = η V , then (op i : M i ) i∈I , η: M η (η V ) is reducible by η .

• M = -• N By induction hypothesis, N is either reducible or a value. As before, we only have to focus on the case when N is a value. From Lemma 3.2.4, we know that N = op V p (λx. M c ) or N = η V . However, we can rule out the former since we know that ∅ ⊢ N : F ∅ (α), meaning that op is not in the empty effect signature ∅. We therefore end up with -• (η V ), which is reducible by -• .

We have shown progress for λ without C. It is easy to see that we cannot do better, as the C operator can violate progress and get us stuck quite easily. Observation 3.2.6. There exists a closed well-typed term M from λ without constants that is neither a value nor reducible to some other term.

Proof. The most trivial example is C (λx. x). The computation that is performed by the body of the function λx. x is entirely determined by the parameter x. It is therefore not possible to pull out this structure outside of the function. Therefore, applying the C operator to this function is undefined and evaluation gets stuck.

Algebraic Properties

In this section, we will clarify what we mean when we say that the F E (α) computation types form a functor/applicative functor/monad and we will prove that the constructions in λ conform to the laws of these algebraic structures.

The object on which we will build these mathematical structures will be the meanings of λ terms. We will therefore start by building an interpretation for λ , a denotational semantics. Then we will be in measure to define the algebraic structures mentioned above and verify that their laws are satisfied.

Denotational Semantics

We start by identifying the domains of interpretation. For each type, we designate a set such that all terms having that type will be interpreted in that set. Before we do so, we introduce some notation on sets. Notation 3.3.1. Let A and B be sets. Then:

• A B is the set of functions from B to A • A × B is the cartesian product of A and B • A ⊔ B is the disjoint union of A and B 43
• A ⊥ is the disjoint union of A and {⊥} Definition 3.3.2. Given a set A ν for every atomic type ν, the interpretation of a type τ is a set τ defined inductively by:

ν = (A ν ) ⊥ α → β = ( α → β ) ⊥ F E (γ) = ( γ ⊔ ⊔ op:α↣β∈E α × F E (γ) β ) ⊥
Note that F E (γ) is recursively defined not only by induction on the type itself but also by its use of F E (γ) on the right hand side. Formally, we take F E (γ) to be the least fixed point of the monotone functional F (X) = ( γ ⊔ ⊔ op:α↣β∈E α × X β ) ⊥ , whose existence is guaranteed by the Knaster-Tarski theorem [77, 126].

Notation 3.3.3. We will use λ notation to write down elements of α → β :

• λx. F (x) ∈ α → β when F (x) ∈ β for every x ∈ α • ⊥ ∈ α → β
We will use the following syntax to write down elements of F E (γ) :

• η(x) ∈ F E (γ) with x ∈ γ • op(p, c) ∈ F E (γ) with op : α ↣ β ∈ E, p ∈ α and c ∈ F E (γ) β • ⊥ ∈ F E (γ)
The definition of τ follows the definition of a value (Definition 3.2.3): function types denote functions and computation types either denote atomic algebraic expressions (η) or applications of algebraic operations (op). In the denotational semantics, we also take care of the fact that terms can get stuck and fail to yield the expected value. We represent this by adding the element ⊥ to the interpretation of every type. Definition 3.3.4. We define the interpretation of a typing context Γ as the set Γ of functions that map every

x : α ∈ Γ to an element of α .

We will call these functions valuations. We will use the notation e[x := f ] to stand for the extension of e with x → f . The domain of the extension is dom(e) ∪ x. The extension maps x to f and every other variable in its domain to e(x). x (e) = e(x)

M N (e) = { M (e)( N (e)), if M (e) is a function ⊥, if M (e) is ⊥ c (e) = I(c) op M p (λx. M c ) (e) = op( M p (e), λX. ( M c (e[x := X]))) η M (e) = η( M (e)) (op i : M i ) i∈I , η: M η N (e) = (op i : M i ) i∈I , η: M η (e)( N (e)) -• M (e) = { x, if M (e) = η(x) ⊥, otherwise C M (e) = C ( M (e))
Definition 3.3.6. The interpretation of a handler (op i : M i ) i∈I , η: M η within a valuation e (also written as

(op i : M i ) i∈I , η: M η (e))
is the function h defined inductively by:

h(η(x)) = { M η (e)(x), if M η (e) is a function ⊥, otherwise h(op j (p, c)) =      M j (e)(p)(λx. h(c(x))), if j ∈ I,
h(⊥) = ⊥
The equations defining h use h on the right-hand side. Nevertheless, h is well-defined since we can rely on induction. There is a well-founded ordering on the elements of F E (γ) , where ∀x. op(p, c) > c(x).

The monotonic functional

F (X) = ( γ ⊔ ⊔ op:α↣β∈E α × X β ) ⊥ used in defining F E (γ) (Defini- tion 3.3.
2) is also Scott-continuous (i.e. it is both monotonic and it preserves suprema). By Kleene fixed-point theorem [74], we have that the least fixed point of F is the supremum of the series ∅ ⊆ F (∅) ⊆ F (F (∅)) ⊆ . . .. Let the rank of x be the smallest n such that x ∈ F n (∅). The ordering < r , defined as x < r y whenever rank(x) < rank(y), is a well-founded ordering. It is also the inductive ordering that we were looking for. Whenever rank(op(p, c)) = n, then c is a function whose codomain is F n-1 (∅) and therefore ∀x. op(p, c) > r c(x). Definition 3.3.7. The interpretation of the C operator is a function g defined inductively by:

g(f ) =      η(h), if f is a function and ∃h. ∀x. f (x) = η(h(x))
op(p, λy. g(λx. c(x)(y))), if f is a function and ∃op, p, c. ∀x. f (x) = op(p, c(x))

⊥, otherwise

As with Definition 3.3.6, we have to show that this is actually a valid definition since we are using g on the right-hand side of an equation defining g. This time around, the arguments to g are functions whose codomain is the interpretation of some computation type F E (β). We can extend a well-founded ordering on the set F E (β) to a well-founded ordering on α → F E (β) by stating that f < g whenever f and g are both functions (not ⊥) and ∀x ∈ α . f (x) < g(x).

Chapter 3. Properties

We have to show that the recursive call to g in the definition above is performed on an argument which is smaller than the original function. Let f ′ = λx. c(x)(y) be the function to which we recursively apply g. We have that f (x) = op(p, c(x)) and f ′ (x) = c(x)(y). We know that ∀y. op(p, c(x)) > c(x)(y), since that is the property of the well-founded ordering on the elements of F E (γ) established above. Therefore, we have that

∀x ∈ α . f (x) > f ′ (x) and so f > f ′ .
This was the entire definition of our denotational semantics. [START_REF] Marcelo P Fiore | Abstract syntax and variable binding[END_REF] We will now compare it to the reduction semantics introduced in 1.4. Proof. The property relies on two facts: that our denotational semantics is compositional, which means that the context closure of reduction rules preserves denotations, and that every individual reduction preserves denotations. To prove so for the β rule is a matter of proving a lemma stating that M (e[x :=

N (e)]) = M [x := N ] (e), which follows from the compositionality of the denotational semantics. For all the other rules, it suffices to use the definition of interpretation (Definition 3.3.5) to calculate the denotation of both the left-hand side and the right-hand side and verify that they are the same object.

We see that equalities from the reduction semantics are carried over to the denotational semantics. The converse, however, is not the case.

Observation 3.3.9. Incompleteness of reduction w.r.t. denotations

There exist terms M and N in λ such that M = N but M and N are not convertible.

Proof. Consider a stuck term such as M = C (λx. x) and another term N = M = (C (λx. x)). Neither one of these two terms is reducible and neither one is a value. They are stuck and the denotational semantics assigns the value ⊥ to both of them, therefore M = N . However, as a consequence of confluence (coming up in 3.4), a pair of different normal terms is never convertible, and therefore M and N are not convertible.

And this concludes the definition of the denotational semantics of λ . Throughout most of the manuscript, we will be using the reduction semantics introduced in 1.4, even though it is incomplete, since it allows us to simplify terms in a mechanical and transparent step-by-step manner. However, the denotational semantics will be useful to us in the rest of this section since it will let us access extra equalities needed to prove some general laws.

Category

We aim to show that the computation types in λ form a functor, applicative functor and a monad. All these terms are defined w.r.t. some category and so we will start by introducing the category underlying λ .

Definition 3.3.10. A category consists of:

• a set of objects • for every two objects A and B, a set of arrows from A to B (an arrow f from A to B is written as f : A → B)

• for any two arrows f : B → C and g : A → B, there exists the composition of the two arrows f • g : A → C

• for any object A, there exists a special arrow id A : A → A [START_REF] Marcelo P Fiore | Abstract syntax and variable binding[END_REF] We could also extend this interpretation to sums and products. The types would be interpreted by α × β = ( α × β ) ⊥ and α + β = ( α ⊔ β ) ⊥ . The term level definitions would be the standard definitions one would expect for pairs and variants (modulo the treatment of ⊥).

Algebraic Properties

51

• the following equations hold for any f : C → D, g : B → C and h : A → B:

(f • g) • h = f • (g • h) (Associativity) (3.1) id D • f = f (Left identity) (3.2) f • id C = f (Right identity) (3.3)
We will be working with a particular category, which we will call λ . The λ category consists of:

objects: the types of the λ calculus arrows: for any two types α and β, the arrows from α to β are the functions from α to β composition: composition of arrows is defined as composition of functions identities: for every type α, we define id α as the identity function with domain α

Since the arrows in our category are functions, the three laws of a category (associativity (3.1), left identity (3.2) and right identity (3.3)) fall out of the same properties for functions.

The Three Laws

Monads form a subset of applicative functors which in turn is a subset of functors. Instead of incrementally building up from a functor all the way to a monad, it will end up being more practical to first prove the monad laws and then illustrate how they let us verify the functor and applicative functor laws. Therefore, we first define our monadic bind operator and prove the three monad laws. Definition 3.3.11. Let X be from F E (α) and f be a function from α to F E (β) . We define X ≫= f inductively on the structure of X:

op(p, c) ≫= f = op(p, λx. c(x) ≫= f ) η(x) ≫= f = f (x) ⊥ ≫= f = ⊥ Note that X ≫= f is equivalent to x ≫= y ([x → X, y → f ]).
Law 3.3.12. (Associativity of ≫=) Let X be from F E (α) , f be a function from α to F E (β) and g be a function from β to F E (γ) . Then the following equation holds:

(X ≫= f ) ≫= g = X ≫= (λx. f (x) ≫= g) Proof.
Proof by induction on the well-founded structure of X: Let η(x) be from F E (α) and f be a function from α to F E (β) . Then the following holds:

• X = ⊥ (⊥ ≫= f ) ≫= g = ⊥ ≫= g = ⊥ = ⊥ ≫= (λx. f (x) ≫= g) • X = η(x) (η(x) ≫= f ) ≫= g = f (x) ≫= g = (λx. f (x) ≫= g)(x) = η(x) ≫= (λx. f (x) ≫= g) • X = op(p, c) (op(p, c) ≫= f ) ≫= g =
η(x) ≫= f = f (x)
Proof. Follows immediately from the definition of ≫= (Definition 3.3.11).

Law 3.3.14. (Right identity for ≫=)

Let X be from F E (α) . Then the following holds:

X ≫= (λx. η(x)) = X
Proof. By induction on the structure of X:

• X = ⊥ ⊥ ≫= (λx. η(x)) = ⊥ • X = η(x) η(x) ≫= (λx. η(x)) = (λx. η(x))(x) = η(x) • X = op(p, c) op(p, c) ≫= (λx. η(x)) = op(p, λy. c(y) ≫= (λx. η(x)))
= op(p, λy. c(y))

= op(p, c)

Functor

We • for every object A in C, an object F (A) in D

• for every arrow

f : A → B in C, an arrow F (f ) : F (A) → F (B) in D
• the following equations hold:

F (f • g) = F (f ) • F (g) (Composition) (3.4) F (id A ) = id F (A) (Identity) (3.5) Definition 3.3.16.
An endofunctor is a functor from some category C to the same category.

For every effect signature E, we will show that F E is an endofunctor on the λ category.

objects: for every type α, we have a type F E (α)

arrows: for every function f : α → β , we have a function

F E (f ) = λX. X ≫= (λx. η(f (x))) : F E (α) → F E (β)
We also need to prove that F E satisfies the necesary laws. Composition (3.4):

F E (f ) • F E (g) = λX. F E (f )(F E (g)(X)) (1)
= λX. F E (f )((λZ. Z ≫= (λx. η(g(x))))(X)) (2)
= λX. F E (f )(X ≫= (λx. η(g(x)))) (3)
= λX. (λZ. Z ≫= (λy. η(f (y))))(X ≫= (λx. η(g(x)))) (4)
= λX. (X ≫= (λx. η(g(x)))) ≫= (λy. η(f (y)))

= λX. X ≫= (λz. (λx. η(g(x)))(z) ≫= (λy. η(f (y))))

= λX. X ≫= (λz. η(g(z)) ≫= (λy. η(f (y))))

= λX. X ≫= (λz. (λy. η(f (y)))(g(z)))

= λX. X ≫= (λz. η(f (g(z))))

= λX. X ≫= (λz. η((f • g)(z))) (9)
= F E (f • g) (10)
Throughout most of the proof, we rely only on the definitions of function composition and the F E (f ) function lifter. On Line 6 though, we make use of the associativity law of ≫= (3.3.12).

Identities (3.5):

F E (id α ) = λX. X ≫= (λx. η(id α (x))) (1)
= λX. X ≫= (λx. η(x))

= λX. X

= id FE (α) (3)
Here, we make use of the right identity law of ≫= (3.3.14) on Line 3. And so we have a functor F E . Its laws let us think of computations of type F E (α) as containing values of type α over which we can map functions the same way one would map a function over a list, satisfying the same basic laws.

We also note that λ already has syntax for this kind of mapping:

F E (f )(X) = x •≫ y ([x → f, y → X]
) where •≫ is the operator introduced in 1.6.1.

Applicative Functor

The two remaining structures, applicative functors and monads, both have two popular and slightly different presentations. One is in terms of natural transformations and is very common in category theory, whereas the other is given in terms of combinators and is preferred in functional programming. Since we will not be using category theory in the rest of this thesis and we will work with lots of combinators, we will focus on the presentation favored in functional programming.

Definition 3.3.17. An applicative functor [91] is a functor F alongside with two combinators, pure : α → F (α) and ⊛ : [START_REF] Geurts | Layered drt[END_REF] polymorphic in α and β. [START_REF] Geurts | Quotation in context[END_REF] Furthermore, the following laws must hold:

F (α → β) → F (α) → F (β)
48 pure(id) ⊛ u = u (Identity) (3.6) pure(•) ⊛ u ⊛ v ⊛ w = u ⊛ (v ⊛ w) (Composition) (3.7) pure(f ) ⊛ pure(x) = pure(f (x)) (Homomorphism) (3.8) u ⊛ pure(x) = pure(λf. f (x)) ⊛ u (Interchange) (3.9)
The intuition is that the functor F adds some notion of computational effect. F (α) is the type of computations having that effect and producing a value of type α. The pure combinator injects a value into the domain of computations without doing anything on the effect level. The ⊛ operator is then meant as a sequencing of two computations: one yielding a function and the other yielding its argument.

The identity law makes sure that pure is indeed pure and does not add any meaningful effect: the effect of pure must in no way tamper with the effect of u. The composition law tells us that the ⊛ operator must be associative: at the level of effects, there is some monoidal structure, where order matters but bracketing does not. The homomorphism law makes sure that ⊛ does actually perform function application. Finally, the interchange law guarantees that ⊛ is not one-sided: the effect of u is respected, no matter if it occurs to the left or to the right of ⊛.

To show that F E is an applicative functor, we will need to define pure and ⊛ and prove the four applicative functor laws.

pure(x) = η(x) F ⊛ X = F ≫= (λf. X ≫= (λx. η(f (x))))
Now, we prove the laws.

Identity (3.6): pure(id) ⊛ u = η(id) ⊛ u (1) = η(id) ≫= (λf. u ≫= (λx. η(f (x)))) (2)
= (λf. u ≫= (λx. η(f (x))))(id) (3)
= u ≫= (λx. η(id(x))) (4)
= u ≫= (λx. η(x)) (5)
= u

We make use of the left and right identities of ≫= on Lines 3 and 6, respectively. [START_REF] Geurts | Layered drt[END_REF] ⊛ is an infix operator that associates to the left, same as application (which it is based on). [START_REF] Geurts | Quotation in context[END_REF] This means that the combinators should not have different definitions for different instances of the type variables α and β. [START_REF] Giorgolo | Monads for conventional implicatures[END_REF] In the Composition Law (3.7), (•) is the function composition combinator.

Composition (3.7):

pure(•) ⊛ u ⊛ v ⊛ w = pure(λf gx. f (g(x))) ⊛ u ⊛ v ⊛ w (1) = η(λf gx. f (g(x))) ⊛ u ⊛ v ⊛ w (2) = (η(λf gx. f (g(x))) ≫= (λf. u ≫= (λx. η(f (x))))) ⊛ v ⊛ w (3) = ((λf. u ≫= (λu ′ . η(f (u ′ ))))(λf gx. f (g(x)))) ⊛ v ⊛ w (4) = (u ≫= (λu ′ . η((λf gx. f (g(x)))(u ′ )))) ⊛ v ⊛ w (5) = (u ≫= (λu ′ . η(λgx. u ′ (g(x))))) ⊛ v ⊛ w (6) = ((u ≫= (λu ′ . η(λgx. u ′ (g(x))))) ≫= (λf. v ≫= (λv ′ . η(f (v ′ ))))) ⊛ w (7) = (u ≫= (λu ′ . η(λgx. u ′ (g(x))) ≫= (λf. v ≫= (λv ′ . η(f (v ′ )))))) ⊛ w (8) = (u ≫= (λu ′ . (λf. v ≫= (λv ′ . η(f (v ′ ))))(λgx. u ′ (g(x))))) ⊛ w (9) = (u ≫= (λu ′ . v ≫= (λv ′ . η((λgx. u ′ (g(x)))(v ′ ))))) ⊛ w (10) = (u ≫= (λu ′ . v ≫= (λv ′ . η(λx. u ′ (v ′ (x)))))) ⊛ w (11) = (u ≫= (λu ′ . v ≫= (λv ′ . η(λx. u ′ (v ′ (x)))))) ≫= (λf. w ≫= (λw ′ . η(f (w ′ )))) (12) = u ≫= (λu ′ . v ≫= (λv ′ . η(λx. u ′ (v ′ (x)))) ≫= (λf. w ≫= (λw ′ . η(f (w ′ ))))) (13)
= u ≫= (λu ′ . v ≫= (λv ′ . η(λx. u ′ (v ′ (x))) ≫= (λf. w ≫= (λw ′ . η(f (w ′ )))))) (14)
= u ≫= (λu ′ . v ≫= (λv ′ . (λf. w ≫= (λw ′ . η(f (w ′ ))))(λx. u ′ (v ′ (x))))) (15)
= u ≫= (λu ′ . v ≫= (λv ′ . w ≫= (λw ′ . η((λx. u ′ (v ′ (x)))(w ′ ))))) (16)
= u ≫= (λu ′ . v ≫= (λv ′ . w ≫= (λw ′ . η(u ′ (v ′ (w ′ )))))) (17)
= u ≫= (λu ′ . v ≫= (λv ′ . w ≫= (λw ′ . (λx. η(u ′ (x)))(v ′ (w ′ ))))) (18)
= u ≫= (λu ′ . v ≫= (λv ′ . w ≫= (λw ′ . η(v ′ (w ′ )) ≫= (λx. η(u ′ (x)))))) (19)
= u ≫= (λu ′ . v ≫= (λv ′ . (w ≫= (λw ′ . η(v ′ (w ′ )))) ≫= (λx. η(u ′ (x))))) (20)
= u ≫= (λu ′ . (v ≫= (λv ′ . w ≫= (λw ′ . η(v ′ (w ′ ))))) ≫= (λx. η(u ′ (x)))) (21)
= u ≫= (λu ′ . (v ⊛ w) ≫= (λx. η(u ′ (x)))) (22)
= u ⊛ (v ⊛ w) (23)
This law relies heavily on the associativity of ≫= (3.3.12). At the beginning, the expression is associated to the left: ((pure(•) ⊛ u) ⊛ v) ⊛ w. And at the end, it associated to the right: u ⊛ (v ⊛ w). In the first part of the proof, we use left identity (Lines 4, 9 and 15) and associativity (Lines 8, 13 and 14). We reach a normal form on Line 17 and start expanding the term again. We expand using left identity on Line 19 and then we reassociate using associativity on Lines 20 and 21. The rest of the equalities is due to the definitions of pure and ⊛ and β reduction.

Homomorphism (3.8):

pure(f ) ⊛ pure(x) = η(f ) ⊛ η(x) (1)
= η(f ) ≫= (λf ′ . η(x) ≫= (λx ′ . η(f ′ (x ′ )))) (2)
= (λf ′ . η(x) ≫= (λx ′ . η(f ′ (x ′ ))))(f ) (3) = η(x) ≫= (λx ′ . η(f (x ′ ))) (4) = (λx ′ . η(f (x ′ )))(x) (5) = η(f (x)) (6)
= pure(f (x))

This proof is very direct. We just have to normalize the term using the left identity of ≫= (3.3.13).

Interchange (3.9):

pure(λf. f (x)) ⊛ u = η(λf. f (x)) ⊛ u (1) = η(λf. f (x)) ≫= (λf ′ . u ≫= (λu ′ . η(f ′ (u ′ )))) (2)
= (λf ′ . u ≫= (λu ′ . η(f ′ (u ′ ))))(λf. f (x)) (3)
= u ≫= (λu ′ . η((λf. f (x))(u ′ ))) (4)
= u ≫= (λu ′ . η(u ′ (x))) (5)
= u ≫= (λu ′ . (λx ′ . η(u ′ (x ′ )))(x)) (6)
= u ≫= (λu ′ . η(x) ≫= (λx ′ . η(u ′ (x ′ )))) (7)
= u ⊛ η(x) (8)
= u ⊛ pure(x) (9)
We start with the law's right-hand side and normalize it on Line 5. Then we do some expansions (left identity on Line 7) to get the desired form.

And there we are, we now have an applicative functor. Applicative functors are very similar to monads, which we will cover in the next part. The trade-off between the two is in terms of expressivity vs composability. When we have two applicative functors, we can compose them and recover pure and ⊛ such that they both satisfy the necessary laws. However, the same is as not easy with monads and one has to go a level higher and compose monad transformers. On the other hand, when chaining two computations within a monad, we can use an operator which lets the effects of the second computation depend on the result of the first, whereas when chaining two computations within an applicative functor, the effects of both computations must be independent.

Oleg Kiselyov explores the use of applicative functors for natural language semantics in his recent Applicative Abstract Categorial Grammars [68, 69]. The composability of applicative functors facilitates the combination, which is the objective of our method as well. However, partly in order to compensate for the limited expressivity of applicative functors, several interpretation passes are required until the logical form of a sentence is constructed.

The two combinators that make up an applicative functor are accessible in λ . The pure operator is the function η and ⊛ is the combinator ≪•≫ introduced in 1.6.1.

Monad Definition 3.3.18.

A monad is a functor F and two combinators, η : α → F (α) and ≫= : F (α) → (α → F (β)) → F (β), polymorphic in α and β. These objects must also satisfy the following laws:

(X ≫= f ) ≫= g = X ≫= (λx. f (x) ≫= g) (Associativity) (3.10) η(x) ≫= f = f (x) (Left identity) (3.11) X ≫= η = X (Right identity) (3.12)
To understand why the laws look the way they do, we will consider functions of type α → F (β). These are the kinds of functions one might use to model call-by-value [95, 94]: we take a value α and then yield some computation F (β). Now assume we would use this type of functions to model procedures of input type α and output type β and we would want these procedures to form a category. For every type α, we would like an identity procedure with input type and output type α, therefore a function of type α → F (α). The polymorphic η combinator will be this identity procedure. We would also like to be able to compose a procedure from α to β with a procedure from β to γ, i.e. compose functions of types α → F (β) and β → F (γ). When composing f : α → F (β) with g : β → F (γ), we run into the problem of having some f (x) : F (β) and g : β → F (γ) that we cannot compose. This is where ≫= comes in and composes these two values for us. Let f >= > g = λx. f (x) ≫= g be the resulting composition operator. In order for this structure to be a category, it needs to satisfy the following:

3.3. Algebraic Properties 57 (f >= > g) >= > h = f >= > (g >= > h) η >= > f = f f >= > η = f
By taking f to be the constant function that returns X, we end up with the laws of the monad. Conversely, with the principle of extensionality, we can derive these laws from the monad laws. Therefore ⟨F, η, ≫=⟩ forms a monad whenever the derived >= > and η form a category. This kind of category is called a Kleisli category and the particular presentation of a monad that we have given here is known as a Kleisli triple.

To prove that F E is a monad will be trivial: we have already done so! The η combinator is of course our η and ≫= is our ≫=. The three laws that we need to verify are three laws that we have introduced in 3.3.3 and have been using throughout this section.

Monads have been introduced to natural language semantics by Chung-chieh Shan in 2002 [113]. Since then, they have seen occasional use, mostly to handle dynamics without burdening the semantics with context/continuation passing [128, 25], but also other phenomena such as conventional implicature/opacity [51, 48, 49]. The challenge of combining different phenomena which rely on different monads has been tackled from two angles: using distributive laws for monads [50] and using monad transformers [27, 13].

In the λ calculus, the monadic operations η and ≫= are available as the η constructor and the ≫= combinator introduced in 1.6.1.

Free Monad

A free monad is a construction of a monad such that the resulting monad satisfies the monad laws but does not satisfy anything more than that. This is similar to the idea of a free monoid generated by some set A. If we have two expressions from a monoid, we know that the operation is associative and so the grouping does not matter. The only thing that matters is which elements are multiplied and in which order. We can therefore think of the elements of this monoid as lists of values from A. The free monad is a similar construction, but instead of building a monoid out of a set, it builds a monad out of a functor.

Let S be some functor, we define the monad ⟨F, η, ≫=⟩ where:

• F (γ) = γ + S(F (γ)) 49 • η(x) = inl(x) • X ≫= f = case X of {inl(x) → f (x); inr(s) → inr(S(λX ′ . X ′ ≫= f )(s))}
The functor S correspond to our effect signature. For op : α ↣ β, we can define a functor S op (γ) = α×γ β . This represents providing a value of type α and waiting for an answer of type β before continuing with γ. By taking the free monad of this functor, we end up with a monad where after each operation, we continue with a new computation of the same kind until we yield a γ, F (γ

) = γ + α × F (γ) β .
If we want to offer more operations with different input and output types, we can take the coproduct of several functors. For an effect signature E, S E (γ) = ∑ op∈E S op (γ). The resulting free monad then looks like

F (γ) = γ + ∑ op:α↣β∈E α × F (γ) β .
If we replace sums with disjoint unions and types with their interpretations, you almost get the kind of set in which we interpret our computation types in 3.3.1. Importantly, the η and ≫= are the same as the ones of the free monad given above. The only difference between the free monad and the monad used in our interpretation are the occurrences of ⊥. The monad that we used is actually a combination of the F (X) = X ⊥ partiality monad and a free monad.

Free monads are another solution to the combination of different effects within a single calculus, hitherto unexplored in its application to natural language semantics. A very early appearance of this technique dates back to 1994 [24]. It has recently gained prominence with the work on extensible effects and effect handlers [71, 16, 63, 22, 104, 110].

Confluence

The object of our study during this section will be the proof of the confluence property of λ . Informally, it means that a single term cannot reduce to two or more different results. Together with the termination from Section 3.5, this will give us the property that every term yields exactly one result and does so in a finite amount of steps (a property known as strong normalization). Confluence also gives us a strong tool to prove an inequality on terms. If two terms reduce to different normal forms, confluence guarantees us that they are not convertible. Proofs of this property are often mechanical and follow the same pattern. Our strategy will be to reuse a general result which applies one such proof for a general class of rewriting systems. Our rewriting system is a system of reductions on terms and the reductions have side conditions concerning the binding of free variables. A good fit for this kind of system are the Combinatory Reduction Systems (CRSs) of Klop [76].

The main result about CRSs that we will make use of is the following (Corollary 13.6 in [76]).

Theorem 3.4.2. Confluence of orthogonal CRSs

Every orthogonal CRS is confluent.

We will model λ as a CRS. However, η-reduction will deny us orthogonality. We will therefore first prove confluence of λ without η-reduction and then we will manually show that confluence is preserved on adding η-reduction back. The rest of this section will go like this:

• CRS: a formalism for higher-order rewriting (3.4.1)

• λ is a CRS (3.4.2)

• Klop et al [93]: Every orthogonal CRS is confluent (3.4.3) λ -η is an orthogonal CRS ⇒ λ -η is confluent (Lemma 3.4.12) η is an orthogonal CRS ⇒ η is confluent (Lemma 3.4.13)

• λ -η + η is confluent (3.4.4, Theorem 3.4.18) because λ -η and η commute (Lemma 3.4.17)

Combinatory Reduction Systems

A Combinatory Reduction System is defined by an alphabet and a set of rewriting rules. We will first cover the alphabet.

Definition 3.4.4. A CRS alphabet consists of:

• a set Var of variables (written lower-case as x, y, z,…)

• a set MVar of metavariables (written upper-case as M , N , …), each with is own arity • a set of function symbols, each with its own arity Let us sketch the difference between the variables in Var and the metavariables in MVar. The variables in Var are the variables of the object-level terms, in our case it will be the variables of λ . The variables in MVar are the metavariables that will occur in our reduction rules and which we will have to instantiate in order to derive specific application of those rules. In other words, the variables in Var are there to express the binding structure within the terms being reduced and the metavariables in MVar are there to stand in for specific terms when applying a reduction rule. We will only sketch the way that a CRS gives rise to a reduction relation and we will direct curious readers to Sections 11 and 12 of [76].

When we instantiate the metavariables in a CRS rule, we use a valuation that assigns to every n-ary metavariable a term with holes labelled from 1 to n. The instantiation of M (t 1 , . . . , t n ) then replaces the metavariable M using the valuation and then fills the holes labelled 1, . . . , n with the terms t 1 , . . . , t n respectively.

The crucial detail is that in a particular context, a metavariable can only be instantiated with terms M that do not contain any free variables bound in that context. This means that for the instantiation of M to contain a variable bound in its context, M must explicitly take that variable as an argument. All other variables not explicitly declared can therefore be safely assumed to not occur freely within M .

Consider the following examples of β and η-reduction.

(λx. M (x)) N → M (N ) λx. N x → N
More formally written as:

@(λ([x]M (x)), N ) → M (N ) λ([x]@(N, x)) → N
where λ is a unary function symbol and @ is a binary function symbol. In both of the versions, M is a unary metavariable and N is a nullary metavariable. In the rule for β-reduction, we can observe how the idea of instantiating metavariables by terms with holes lets us express the same idea for which we had to introduce the meta-level operation of substitution. In the rule for η-reduction, we see that N appears in a context where x is bound but it does not have x as one of its arguments. Therefore, it will be impossible to instantiate N in such a way that it contains a free occurrence of x. In both of those rules, we were able to get rid of meta-level operations (substitution) and conditions (x / ∈ F V (N )) and have them both implemented by the formalism itself.

λ as a CRS

We will now see how to rephrase the reduction rules of λ in order to fit in to the CRS framework. We have already seen how to translate the β and η rules in the previous subsection. The next rules to address are the rules defining the semantics of the handlers. We will repeat the rules for handlers to make the issue at hand clear.

(op i : M i ) i∈I , η: M η (η N ) → rule η M η N (op i : M i ) i∈I , η: M η (op j N p (λx. N c )) → rule op M j N p (λx. (op i : M i ) i∈I , η: M η N c ) where j ∈ I and x / ∈ FV((M i ) i∈I , M η ) (op i : M i ) i∈I , η: M η (op j N p (λx. N c )) → rule op ′ op j N p (λx. (op i : M i ) i∈I , η: M η N c )
where j / ∈ I and x / ∈ FV((M i ) i∈I , M η ) The syntax of CRSs does not allow us to use the (op i : M i ) i∈I notation nor capture the j ∈ I or j / ∈ I conditions. The symbols op i are problematic as well, since technically, they are not concrete λ syntax but metavariables standing in for operation symbols.

We do away with all of the above problems by expanding these meta-notations and adding a separate rule for every possible instantiation of the schema. This means that for each sequence of distinct operation symbols op 1 ,…,op n , we end up with:

• a special rewriting rule op

1 : M 1 , . . . , op n : M n , η: M η (η N ) → M η N • for every 1 ≤ i ≤ n, a special rewriting rule op 1 : M 1 , . . . , op n : M n , η: M η (op i N p (λx. N c (x))) → M i N p (λx. op 1 : M 1 , . . . , op n : M n , η: M η N c (x))
• for every op ′ ∈ E \ {op i |1 ≤ i ≤ n}, a special rewriting rule op 1 : M 1 , . . . , op n : M n , η: M η (op ′ N p (λx. N c (x))) → op ′ N p (λx. op 1 : M 1 , . . . , op n : M n , η: M η N c (x)) The rule for the cherry -• extraction operator is already in CRS form, so all we have to do is address the rules for the C operator. We present them side-by-side in their original form and in CRS-style.

Original:

C (λx. η M ) → η (λx. M ) C (λx. op M p (λy. M c )) → op M p (λy. C (λx. M c )) where x / ∈ FV(M p )
CRS-style:

C (λx. η (M (x))) → η (λx. M (x)) C (λx. op M p (λy. M c (x, y))) → op M p (λy. C (λx. M c (x, y)))
We can see that the only difference is to replace "simple" metavariables M , M p and M c with their higher-order versions: the unary M , nullary M p and binary M c . We see that every CRS metavariable is applied to the variables in its scope, except for M p , which thus loses access to the variable x. This way, the condition that x must not appear free in M p is now encoded directly in the reduction rule itself.

In 3.4.1, we have said that a CRS is formed by a set of reduction rules and by an alphabet. We have already seen all of the rules of our CRS (β and η were given at the end of 3.4.1 and the -• rule is the same as the original one in 1.4). In order to have a complete definition, all that remains is to identify the alphabet.

The set of variables V ar is exactly the set of variables X used in the definition of λ . The set of metavariables M V ar consists of the unary M , nullary N , nullary N p , unary N c , nullary M p , binary M c , nullary M i and nullary M η . The set of function symbols is composed of the following: In giving the CRS-style reduction rules above, we have used the "native" syntax of λ instead of writing out everything in terms of function symbols. For clarity, we give the rules governing the relationship of the two. We write:

• @(t, u) as t u

• λ([x]t) as λx. t • η(t) as η t • op(t p , [x]t c ) as op t p (λx. t c ) 50 • ( op 1 : _, . . . , op n : _, η: _ _)(t 1 , . . . , t n , t η , u) as op 1 : t 1 , . . . , op n : t n , η: t η u • -• (t) as -• t • C(t) as C t
We have connected the terms of λ with CRS terms and we have also expressed all of our reduction rules in terms of CRS reduction rules. As in λ , CRS then proceeds to take a context closure of this redex-contractum relation. Our translation from λ to a CRS also preserves subterms [START_REF] Giorgolo | Multidimensional semantics with unidimensional glue logic[END_REF] and so we end up constructing the same reduction relation.

Orthogonal CRSs

In order to use Theorem 3.4.2, we need to show that our CRS is orthogonal, so let us start us by looking at what "orthogonal" means in the context of CRSs. Definition 3.4.9. A CRS is orthogonal if it is non-overlapping and left-linear.

We will need to satisfy two criteria: no overlaps and left linearity. We will start with the latter.

Definition 3.4.10. A CRS is left-linear if the left-hand sides of all its reduction rules are linear. A CRS metaterm is linear if no metavariable occurs twice within it.

By going through the rules we have given in 3.4.2, we can see at a glance that no rule uses the same metavariable twice in its left-hand side and so our CRS is indeed left-linear. • Let r = s → t be some reduction rule of the CRS and let M 1 ,…,M n be all the metavariables occurring in the left-hand side s. Whenever we can instantiate the metavariables in s such that the resulting term contains a redex for some other rule r ′ , then said redex must be contained in the instantiation of one of the metavariables

M i .
• Similarly, whenever we can instantiate the metavariables in s such that the resulting term properly contains a redex for the same rule r, then that redex as well must be contained in the instantiation of one of the metavariables M i .

In simpler words, no left-hand side of any rule can contain bits which look like the top of the left-hand side of some other rule. Let us try and verify this property in λ :

• The rules have no overlaps with any of the other rules. Their left-hand sides are constructed only of the symbols and the op and η constructors. Since there is no reduction rule headed by op and η, they have no overlap with any of the other rules. Furthermore, the three rules are mutually exclusive, so there is no overlap between themselves.

• The -• rule does not overlap with any of the other neither, since the left-hand side contains only -• and η, and there is no reduction rule headed by η.

• The C rules are both mutually exclusives, so there is no overlap between the two. However, their lefthand sides are built not only out of C, op and η, but also of λ, for which there is the η-reduction rule. Fortunately, in this case, the C rules only apply when the λ-abstraction's body is an η expression or an op expression, whereas the η rule applies only when the body is an application expression. [START_REF] Giorgolo | Coreference without discourse referents: a nonrepresentational drt-like discourse semantics[END_REF] Therefore, there is no overlap.

We have established that all the reduction rules in our system are pairwise non-overlapping except for β and η. However, these two have a notorious overlap.

We can instantiate the metavariables in the left-hand side of the β rule to get a term which contains an η-redex which shares the λ-abstraction with the β-redex.

(λx. y x) z

We can also instantiate the metavariables in the left-hand side of the η rule to create a β-redex which shares the application with the η-redex. λx. (λz. z) x Because of these overlaps, the λ CRS is therefore not orthogonal. However, we can still make good use of Theorem 3.4.2.

Lemma 3.4.12. Confluence of λ -η

The λ reduction system without the η rule is confluent.

Proof. If we exclude the η rule, we have a CRS which is left-linear and also non-overlapping. [START_REF] Groenendijk | Dynamic predicate logic[END_REF] Therefore, it is orthogonal and thanks to Theorem 3.4.2, also confluent.

Lemma 3.4.13. Confluence of η-reduction

The reduction system on λ terms containing only the η-reduction rule is confluent. 54 Proof. We have seen that η is a valid left-linear CRS rule. It also does not overlap itself since its left-hand side does not contain any λ subexpression. The CRS consisting of just the η rule is therefore orthogonal and confluent.

Putting η Back in λ

We have shown that both λ -η and η are confluent. The reduction relation of the complete λ calculus is the union of these two reduction relations. Using the Lemma of Hindley-Rosen (1.0.8.(2) in [75]), we can show that this union is confluent by showing that the two reduction relations commute together. Lemma of Hindley-Rosen [75] Let → 1 and → 2 be two confluent reduction relations on the same set of terms. If → 1 and → 2 commute, then the reduction relation → 1 ∪ → 2 is confluent.

We will not be proving the commutativity directly from the definition. Instead, we will use a lemma due to Hindley (1.0.8.(3) in [75]). Lemma 3.4.16. Let → 1 and → 2 be two reduction relations on the same set of terms A. Suppose that whenever there are a, b, c ∈ A such that a → 1 b and a → 2 c, there is also some

d ∈ A such that b ↠ 2 d and c → = 1 d (meaning c → 1 d or c = d).
In that case, → 1 commutes with → 2 . [75] We can use this to prove that λ -η commutes with the η-reduction rule.

Lemma 3.4.17. Commutativity of η and λ -η

The reduction relations induced by η and by the rest of the λ rules commute.

Proof. We will prove this lemma by an appeal to Lemma 3.4.16. Let → η be the reduction relation induced by the rule η and → λ -η the reduction relation induced by all the other reduction rules in λ . We need to prove that for all terms a, b and c where a → λ -η b and a → η c, we have a term d such that b ↠ η d and c → = λ -η d. This will turn out to be a routine proof by induction on the structure of the term a. The base cases are trivial since terms without any proper subterms happen to have no redexes in λ and therefore trivially satisfy the criterion. In the inductive step, we will proceed by analyzing the relative positions of the redexes which led to the reductions a → λ -η b and a → η c. -If a is an application: Since a is an application and also a λ -η -redex, it must match the left-hand side of the β rule, (λx. M (x)) N , and b must be M (N ).

* We will first deal with the case when the η-redex which lead to c originated in M (x). In that case M (x) → η M ′ (x) and c = (λx. M ′ (x)) N . Our sought-after d is then M ′ (N ), since

c → = λ -η d via β in one step and b = M (N ) ↠ η d = M ′ (N )
. * Now we get to one of the two interesting cases which necessitated this whole lemma: the overlap between β and η, with β on the top. If the η-redex did not originate in M (x), then the η-redex must be λx. M (x). Therefore, M = T x and a = (λx. T x) N . Performing the η-reduction yields c = T N . In this case, both b and c are equal to T N and so we can choose T N as our d.

-If a is any other kind of term: Let l → r be the rule used in a → λ -η b. Not counting β, which only acts on applications and which we dealt with just above, the rules of λ -η do not overlap with the η rule. This means the η-redex which led to c must lie entirely inside a part of l which corresponds to a metavariable. Let M be that metavariable, then we will decompose l into L(M ) and r into R(M ). We have a = L(a ′ ) for some a ′ , b = R(a ′ ) and c = L(a ′′ ) [START_REF] Hamana | Higher-order semantic labelling for inductive datatype systems[END_REF] . Our d will be R(a ′′ ) and we have b = R(a ′ ) ↠ η d = R(a ′′ ) in several steps [START_REF] Hillerström | Compiling links effect handlers to the ocaml backend[END_REF] and

c = L(a ′′ ) → = λ -η d = R(a ′′ ) in one step of l → r. • If the redex in a → η c is the entire term a, but the redex in a → λ -η b is a proper subterm of a:
In this case, a must be an abstraction that matches the left-hand side of the η rule, i.e. a = λx. N x. Also, we have c = N .

-As before, we will first deal with the case when the λ -η -redex is contained completely within

N . Then N → λ -η N ′ and b = λx. N ′ x. The common reduct d is N ′ since b ↠ η d in one step and c = N → = λ -η d = N ′ as established before.
-Now this is where we deal with the second overlap between β and η in our reduction system, the one with η on top. The λ -η -redex in a must be N x and the reduction rule in question must therefore be β. Therefore, N = λy. T (y) and a = λx. (λy. T (y)) x. Performing the βreduction gives us b = λx. T (x) which is, however, equal to c = N = λy. T (y). So we can choose d = b and we are done.

• If a is the redex for both reductions a → λ -η b and a → η c, then a must match the left-hand side of a λ -η rule and the η rule. However, this is impossible since the left-hand side of the η rule is headed by abstraction, which is the case for none of the rules of λ -η .

Equipped with this lemma, we can go on to prove our main result, Theorem 3.4.18, the confluence of λ .

Theorem 3.4.18. Confluence of λ

The reduction relation → on the set of λ terms, defined by the reduction rules in 1.4, is confluent.

Proof. From Lemma 3.4.12, we know that the λ -η system is confluent and from Lemma 3.4.13, we know that the η-reduction rule is confluent as well. Lemma 3.4.17 tells us that these two reduction systems commute and therefore, by Lemma 3.4.15, their union, which is the λ reduction system, commutes as well.

Termination Definition 3.5.1. A reduction relation is

terminating if there is no infinite chain M 1 → M 2 → . . ..
In this section, we will prove termination with a similar strategy as the one we employed for confluence. λ is an extension of the λ-calculus with computation types and some operations on computations. Our computations can be thought of as algebraic expressions, i.e. they have a tree-like inductive structure. The reason that all computations in λ terminate is that the operations defined on computations rely on well-founded recursion. However, it is quite tricky to go from this intuition to a formal proof of termination. Fortunately, we can rely on existing results.

Blanqui, Jouannaud and Okada have introduced Inductive Data Type Systems (IDTSs) [20, 19]. Like CRSs, IDTSs are a class of rewriting systems for which we can prove certain interesting general results. In this section, we will start by examining the definition of an IDTS and fitting λ into that definition. The [START_REF] Hamana | Higher-order semantic labelling for inductive datatype systems[END_REF] Since our rules are left-linear, M is guaranteed to appear in L(M ) at most once. Therefore, if a ′ →η a ′′ in one step, then also L(a ′ ) →η L(a ′′ ) in one step as well. [START_REF] Hillerström | Compiling links effect handlers to the ocaml backend[END_REF] a ′ can occur multiple times in R(a ′ ) when the rule l → r is duplicating (which is actually the case for the op rules). However, we are able to go from R(a ′ ) to R(a ′′ ) in multiple steps. NB: This is why we use Lemma 3.4.16 instead of trying to prove commutativity directly. theory of IDTSs comes with a sufficient condition for termination known as the General Schema. λ will not satisfy this condition and so we will first transform it using Hamana's technique of higher-order semantic labelling [55]. As with our proof of confluence, we will first consider the case of λ without η-reduction and then add η manually while preserving termination.

The plan will look like this:

• IDTS = Typed CRS (3.5.1)

• The λ τ IDTS (3.5.2)

if λ τ terminates, then λ -η terminates (Lemma 3.5.11)

• Blanqui [19]: General Schema ⇒ termination (3.5.3)

• Hamana [55]: IDTS R terminates iff the labelled IDTS R terminates (3.5.4) -Theorem 3.5.40: λ τ terminates (via Blanqui [19]) and therefore λ is strongly normalizing (Theorem3.5.47)

-

Inductive Data Type Systems

We will go by the revised definition of Inductive Data Type Systems that figures in [19] and [55]. This formulation extends IDTSs to higher-order rewriting and does so using the CRS formalism that we introduced earlier.

Definition 3.5.2. An Inductive Data Type System (IDTS) is a pair of an IDTS alphabet and a set of IDTS rewrite rules.

Just like a CRS, an IDTS is an alphabet coupled with some rewrite rules. Let us first look at the alphabet and the rules for building terms out of the elements of the alphabet; the rewrite rules will follow. The distinction between a CRS-alphabet and an IDTS alphabet is that the IDTS alphabet comes equipped with a set of types. Furthermore, all the other symbols in the alphabet are indexed by types, so we end up with typed variables, typed function symbols and typed metavariables.

When we consider IDTS metaterms, we admit only well-typed terms. The definition of IDTS metaterms refines the definition of CRS metaterms by restraining term formation in accordance with the types.

Definition 3.5.5. The typed metaterms of an IDTS are given inductively:

• variables from X τ are metaterms of type τ • all the metavariables that occur in t also occur in s

• if t is a metaterm of type β and x a variable from X α , then [x]t is a metaterm of type α ⇒ β called abstraction • if F is an function symbol from F α1,...,
• any metavariable M that occurs in s only occurs in the form M (x 1 , . . . , x k ), where x i are pairwise distinct variables

• s and t are both of the same type

As stated above, an IDTS is just an alphabet along with a set of rewrite rules. An IDTS induces a rewriting relation in exactly the same way as a CRS does, see [19] for more details.

λ as an IDTS

Now we will link λ to the IDTS framework in order to benefit from its general termination results. The biggest obstacle will be that IDTS assigns a fixed type to every symbol. In λ , symbols are polymorphic: the η constructor can produce expressions like η ⋆ : F E (1) or η (λx. x) : F E (α → α) and that for any choice of E. We would therefore like to replace function symbols such as η with specialized symbols η FE (α) . For a given type α and effect signature E, the symbol η FE (α) would have the type α → F E (α), i.e. it would belong to F α,FE (α) . We will call this calculus with specialized symbols λ τ . There will not be a bijection between λ and λ τ since a single term in λ will generally correspond to a multitude of specialized versions in λ τ (think of λx. x in λ versus λx ι . x ι , λx o . x o . . . in λ τ ). Therefore, the results we prove for λ τ will not automatically transfer to λ . In the rest of this subsection, we will elaborate the definition of λ τ and show why termination carries over from λ τ to λ -η . [START_REF] Hobbs | Making computational sense of montague's intensional logic[END_REF] Defining λ τ λ τ will be defined as an IDTS. This means we need to first identify the alphabet. The base types B of λ τ will be the set of types of λ . [START_REF] Hodges | Tarski's truth definitions[END_REF] Note that both λ and IDTS have a notion of function type, but the notation is different. Contrary to common practice, in our exposition of IDTS we use α ⇒ β for the IDTS function type. This allows us to keep using the α → β notation for λ types, as we do in the rest of the thesis.

Next, we will introduce function symbols for all the syntactic constructions of λ , except for abstraction, which is handled by the [_]_ binder construct already found in IDTSs:

• ap α,β ∈ F α→β,α,β (i.e. for every pair of types α and β, there will be a function symbol ap α,β of type

(α → β) ⇒ α ⇒ β in our alphabet) • λ α,β ∈ F α⇒β,α→β • c ∈ F α for any constant c : α ∈ Σ • η α,E ∈ F α,FE (α)
• op γ,E ∈ F α,β⇒FE (γ),FE (γ) for any operation symbol op from E and any E such that op :

α ↣ β ∈ E • -• α ∈ F F ∅ (α),α • op 1 ,...,op n ,γ,δ,E,E ′ ∈ F α1→(β1→F E ′ (δ)),...,αn→(βn→F E ′ (δ)),γ→F E ′ (δ),FE (γ),F E ′ (δ) where: -op 1 : α 1 ↣ β 1 ∈ E, …, op n : α n ↣ β n ∈ E -E \ {op 1 , . . . , op n } ⊆ E ′ • C α,β,E ∈ F α→FE (β),FE (α→β)
The list above is based on the typing rules of λ found on Figure 1.1. We convert the typing rules of λ into the typed function symbols of λ τ with the following process:

• We take a typing rule of λ , other than [var] (since variables are already present in the language of IDTS terms).

• We identify all the type-level metavariables. That is, metavariables α, β, γ . . . ranging over types, metavariables E, E ′ . . . ranging over effect signatures and metavariables op ranging over operation symbols.

• We strip these metavariables down to a minimal non-redundant set (e.g. in the [op] rule, we have that op : α ↣ β ∈ E, therefore E and op determine α and β and α and β are redundant).

• We introduce a family of symbols: for every possible instantiation of the metavariables mentioned above, we will have a different symbol. The arity of the symbol will correspond to the number of typing judgments that serve as hypotheses to the typing rule. The types of the arguments and of the result will be derived from the types of the judgments of the hypotheses and the conclusion respectively. If a variable of type α is bound in a premise of type β, then that will correspond to the IDTS function type α ⇒ β.

-Example: In the [η] rule, we have two metavariables: α standing in for a type and E standing in for an effect signature. The rule has one typing judgment hypothesis. For every type α and every effect signature E, we will therefore have a unary symbol η α,E of type α ⇒ F E (α) (i.e. belonging to F α,F E (α) ).

A specifically-typed symbol in λ τ then corresponds to an instantiation of the type metavariables in a λ typing rule. We can follow this correspondence further and see that λ τ IDTS terms, written using the above function symbols, correspond to typing derivations in λ .

Our alphabet now has types and function symbols. We also need to specify the sets of variables and metavariables and so we will take some arbitrary sets with x τ , y τ , . . . ∈ X τ and M α1,...,αn,β , N α1,...,αn,β , . . . ∈ Z α1,...,αn,β .

To complete our IDTS, we have to give the rewrite rules. The rules for λ τ are given in Figure 3.1. An important property of an IDTS rewrite rule is that both its left-hand and right-hand side are well-typed and that they have the same type. In order to facilitate the reader's verification that this is indeed the case, we have used a different labelling scheme for function symbols. When we write f α1,...,αn,β , we are referring to the instance of symbol f which has the type α 1 ⇒ . . . ⇒ α n ⇒ β (i.e. belongs to F α1,...,αn,β ). This way, instead of using a symbol name like η α,E , forcing you to look up its type α ⇒ F E (α), we will refer to this symbol directly as η α,FE (α) .

ap(λ([x]M (x)), N ) → rules β α,γ M (N ) ap α→γ,α,γ (λ α⇒γ,α→γ ([x α ]M α,γ (x α )), N α ) → M α,γ (N α ) let (op i ) i∈I FE (γ),F E ′ (δ) (N FE (γ) ) = (op i )i∈I (αi→(βi→F E ′ (δ))→F E ′ (δ))i∈I ,γ→F E ′ (δ),FE (γ),F E ′ (δ) ((M i αi→(βi→F E ′ (δ))→F E ′ (δ) ) i∈I , M η γ→F E ′ (δ) , N F E (γ) ) (op i )i∈I (η(N )) → rules η (op i )i∈I FE (γ),F E ′ (δ)
ap(M η , N )

(op i ) i∈I FE (γ),F E ′ (δ) (η γ,FE (γ) (N γ )) → ap γ→F E ′ (δ),γ,F E ′ (δ) (M η γ→F E ′ (δ) , N γ ) (op i )i∈I (op j (N p , [y]N c (y))) → rules op (op i )i∈I F E (γ),F E ′ (δ) ap(ap(M j , N p ), λ([y] (op i )i∈I (N c (y))))
where j ∈ I

(op i )i∈I FE (γ),F E ′ (δ) (op jα,β⇒F E (γ),FE (γ) (N p α , [y β ]N c β,FE (γ) (y β ))) → ap (β→F E ′ (δ))→F E ′ (δ),β→F E ′ (δ),F E ′ (δ) (ap α→(β→F E ′ (δ))→F E ′ (δ),α,(β→F E ′ (δ))→F E ′ (δ) (M j α→(β→F E ′ (δ))→F E ′ (δ) , N p α ), λ β⇒F E ′ (δ),β→F E ′ (δ) ([y β ] (op i ) i∈I FE (γ),F E ′ (δ) (N c β,FE (γ) (y β )))) (op i )i∈I (op j (N p , [y]N c (y))) → rules op ′ (op i )i∈I F E (γ),F E ′ (δ) op j (N p , [y] (op i )i∈I (N c (y)))
where j / ∈ I

(op i )i∈I FE (γ),F E ′ (δ) (op jα,β⇒F E (γ),FE (γ) (N p α , [y β ]N c β,F E (γ) (y β ))) → op jα,β⇒F E ′ (δ),F E ′ (δ) (N p α , [y β ] (op i )i∈I FE (γ),F E ′ (δ) (N c β,FE (γ) (y β ))) -• (η(N )) → rules -• α N -• F ∅ (α),α (η α,F ∅ (α) (N α )) → N α C(λ([x]η(M (x)))) → rules C η α,β,E η(λ([x]M (x))) C α→FE (β),FE (α→β) (λ α⇒FE (β),α→FE (β) ([x α ]η β,FE (β) (M α,β (x α )))) → η (α→β),FE (α→β) (λ α⇒β,α→β ([x α ]M α,β (x α ))) C(λ([x]op(M p , [y]M c (x, y)))) → rules C op α,β,E op(M p , [y]C(λ([x]M c (x, y)))) C α→F E (β),FE (α→β) (λ α⇒FE (β),α→FE (β) ([x α ]op γ,δ⇒FE (β),FE (β) (M p γ , [y δ ]M c α,δ,FE (β) (x α , y δ )))) → op γ,δ⇒F E (α→β),FE (α→β) (M p γ , [y δ ]C α→FE (β),FE (α→β) (λ α⇒FE (β),α→FE (β) ([x α ]M c α,δ,FE (β) (x α , y δ )))) Figure 3.1:
The IDTS rewrite rules for λ τ , shown in parallel with the CRS rules for λ .

In Figure 3.1, you will also find the rewrite rules with all the subscripts removed. This allows you to get a high-level look at the term without any of the type annotation noise. By removing the type indices from the λ τ IDTS rewrite rules, we get the λ CRS-reduction rules of Section 3.4 (modulo the renaming of @ to ap).

When describing the rewrite rules for handlers, we introduce a shortcut

(op i )i∈I FE (γ),F E ′ (δ) (N FE (γ)
), which stands for partially applied to the clauses M i and M η . We then reuse this shortcut in all of the rules.

Connecting λ τ to λ

We have given a complete formal definition of λ τ . This will let us find a proof of termination for λ τ using the theory of IDTSs. However, in order to carry over this result to our original calculus, we will need to formalize the relationship between the two. Definition 3.5.8. Term is a (partial) function from λ τ terms to λ terms which removes any type annotations (the subscripts on function symbols, variables and metavariables) and translates λ τ syntax to λ syntax using the following equations:

Term(x) = x Term(λ([x]M )) = λx. Term(M ) Term(ap(M, N )) = (Term(M )) (Term(N )) Term(c) = c Term(η(M )) = η (Term(M )) Term(op(M p , [x]M c )) = op (Term(M p )) (λx. Term(M c )) Term( -• (M )) = -• (Term(M )) Term( op 1 ,...,op n (M 1 , . . . , M n , M η , N )) = op 1 : Term(M 1 ), op n : Term(M n ), η: Term(M η ) (Term(N )) Term(C(M )) = C (Term(M ))
Definition 3.5.9. Types is a function from λ terms to sets of λ τ terms, defined by the equation below.

Types(M ) = {m | Term(m) = M } Lemma 3.5.10. Let M and N be λ terms. Then, M → λ -η N ⇒ ∀m ∈ Types(M )
. ∃n ∈ Types(N ). m → n In the above, upper-case letters stand for λ terms, while lower-case letters stand for λ τ terms.

Proof. This property is essentially a stronger kind of subject reduction for λ -η . In proofs of subject reduction, we examine every reduction rule and we show how a typing derivation of the redex can be transformed into a typing derivation of the contractum. We can think of λ τ terms as λ typing derivations. The reduction rules in Figure 3.1 are the rules which tell us how to take a typing of the redex and transform it into a typing of the contractum.

In order to prove this property, we will need to check the following:

• The redexes and contracta in Figure 3.1 are well-formed (i.e. well-typed). For that reason, we have included the type of every variable, metavariable and function symbol as a subscript.

• Applying Term to the left-hand and right-hand sides of the λ τ rules yields the left-hand and right-hand sides of all the λ -η rules (and therefore the left-hand and right-hand sides of λ τ rules belong to the Types image of the left-hand and right-hand sides of the λ -η rules). Since in Figure 3.1, we have included the terms with their type annotations removed, we can see at a glance that the stripped rules align with the CRS formulation of λ .

• Finally, we have to check whether the rewriting rules in Figure 3.1 actually apply to all the m ∈ Types(M ). In other words, we need to check whether the type annotation scheme used for the lefthand sides is the most general and covers all possible typings of the left-hand side. This is the case because we have followed the typing rule constraints and given the most general type annotations.

Given a reduction in λ -η from M to N , we can find the untyped reduction rule used in Figure 3.1. We know that if m ∈ Types(M ), then m then matches the left-hand side of the corresponding typed rule. We also know that the right-hand side of the typed rule belongs to Types(N ) and therefore, the property holds. Furthermore, if we were to formalize the correspondence between λ typing derivations and λ τ terms, we would get another proof of subject reduction for λ -η . Lemma 3.5.11. If the reduction relation of λ τ is terminating, then so is the λ -η reduction relation on welltyped terms.

Proof. Consider the contrapositive: if there exists an infinite λ -η chain of well-typed λ terms, we can use Lemma 3.5.10 to translate it, link by link, to an infinite λ τ chain. However, infinite λ τ reduction chains do not exist since λ τ is terminating.

Termination for IDTSs

So far, we have introduced an IDTS and have shown that if this IDTS is terminating, then so is λ -η . We will now look at a general result for IDTSs that we will make use of. Theorem 3.5.12. Strong normalization [19] Let I = (A, R) be a β-IDTS satisfying the assumptions (A). If all the rules of R satisfy the General Schema, then → I is terminating.

The theorem was lifted verbatim [START_REF] Hughes | Generalising monads to arrows[END_REF] from [19] and parts of it deserve explaining:

• What is a β-IDTS?

• What are the assumptions (A)?

• What is the General Schema?

We will deal with these in order. A β-IDTS is an IDTS which, for every two types α and β, has a function symbol @ α,β ∈ F α⇒β,α,β and a rule @ α,β ([x α ]M α,β (x α ), N α ) → M α,β (N α ). Furthermore, there must be no other rules whose left-hand side is headed by @. We can turn our IDTS from 3.5.2 into a β-IDTS by extending it with these function symbols and reduction rules. [START_REF] Hyland | Combining effects: Sum and tensor[END_REF] Termination in a larger system will still imply termination in our system.

Checking Off the Assumptions

Next, we will deal with the assumptions (A).

Definition 3.5.13. The Assumptions (A) are defined as the following four conditions:

1. every constructor is positive 2. no left-hand side of rule is headed by a constructor 3. both > B and > F are well-founded 4. stat f = stat g whenever f = F g For these to make sense to us, we will need to identify some more structure on top of our IDTS: the notion of a constructor and the > B and > F relations.

We will need to designate for every base type γ a set C γ ⊆ ∪ p≥0,α1,...,αp∈T (B) F α1,...,αp,γ (i.e. a set of function symbols with result type γ). We will call the elements of these sets constructors of γ.

The base types of our IDTS consist of atomic types, function types and computation types. We will have no constructors for atomic types. On the other hand, every function type α → β will have a constructor λ α,β (∈ F α⇒β,α→β ) and every computation type F E (γ) will have constructors η γ,E (∈ F γ,FE (γ) ) and op γ,E (∈ F α,β⇒FE (γ),FE (γ) ) for every op : α ↣ β ∈ E.

We can now check assumption (A.2). Since the only constructors in our IDTS are η, op and λ, we validate this assumption. [START_REF] Mark | Functional programming with overloading and higher-order polymorphism[END_REF] Our choice of constructors induces a binary relation on the base types.

Definition 3.5.14. The base type α depends on the base type β if there is a constructor c ∈ C α such that β occurs in the type of one of the arguments of c.

We will use ≥ B to mean the reflexive-transitive closure of this relation. Furthermore, we will use = B and > B to mean the associated equivalence and strict ordering, respectively.

Observation 3.5.15. If τ 1 ≤ B τ 2 , then τ 1 is a subterm of τ 2 .
Proof. We will prove this by induction on the structure of the base type τ 2 . If τ 2 is an atomic type, then τ 2 has no constructors, so it does not depend on any other type. If we look at the reflexive-transitive closure of that, ≥ B , then the only type α such that τ 2 ≥ B α is, by reflexivity, τ 2 itself, which is a subterm of τ 2 .

If τ 2 is the computation type F E (γ), then we will have several constructors. We have η γ,E with a single argument of type γ. We thus know that F E (γ) depends on γ. For every op : α ↣ β ∈ E, we have a constructor op γ,E with arguments of types α and β ⇒ F E (γ). This tells us that F E (γ) also depends on α, β and F E (γ). F E (γ) does not have any more constructors, so those are all the types it depends on. The ≥ B relation, which is the subject of this observation, is the reflexive-transitive closure of the dependency relation between base types. This means that τ

2 ≥ B τ 1 if either τ 2 = τ 1 or τ 2 depends on some τ ′ 2 ̸ = τ 2 such that τ ′ 2 ≥ B τ 1 . • If τ 2 = τ 1 ,
then trivially τ 1 is a subterm of τ 2 and we are done.

• If τ 2 depends on some τ ′ 2 ̸ = τ 2 , then τ ′ 2 must be either γ or one of the α or β from E since τ 2 = F E (γ). In all these cases, we can apply the induction hypothesis for τ ′ 2 . We know that τ ′ 2 ≥ B τ 1 and by the induction hypothesis, we now know that τ 1 is a subterm of τ ′ 2 . Since τ ′ 2 is a subterm of τ 2 , we have that τ 1 is a subterm of τ 2 .

Corollary 3.5.16. If

τ 1 = B τ 2 , then τ 1 = τ 2 . Corollary 3.5.17. If τ 1 < B τ 2 , then τ 1 is a proper subterm of τ 2 .
We can now check assumption (A.3). Since the proper subterm relation is well-founded (i.e. has no infinite descending chains) and > B is a subset of the proper subterm relation, then > B must be wellfounded as well.

We can also check assumption (A.1) once we explain what a strictly positive type is.

Pos(α ⇒ β) = Neg(α) ∪ Pos(β) Neg(α ⇒ β) = Pos(α) ∪ Neg(β)
Pos(ν) = {ν} with ν an atomic type Neg(ν) = ∅ with ν an atomic type 72

Chapter 3. Properties

In our IDTS, α = B β is true only when α = β. The only time a base type occurs in the type of one of its constructor's arguments is in the case of the op constructors. Given op : α ↣ β ∈ E, op γ,E is a constructor of F E (γ); the type of its second argument is β ⇒ F E (γ). This occurrence is positive and so we validate assumption (A.1).

To validate the second half of (A.3), we will need to introduce the > F relation. As > B was induced by the structure of constructors, > F will be induced by the structure of the rewriting rules R of our IDTS. Definition 3.5.20. A function symbol f depends on a function symbol g if there is a rule defining f (i.e. whose left-hand side is headed by f ) and in the right-hand side of which g occurs.

We will use ≥ F as the name for the reflexive-transitive closure of this relation. We will also write = F and > F for the associated equivalence and strict ordering, respectively.

If we scan the rules of λ , we will see that the symbols depend on op (for when there is no handler and the op is copied), ap (for applying the handler clauses to their arguments), λ (for the continuation) and on (for recursion). The C symbols depend on op (when passing the λ through an op), η (when switching the λ with the η), λ (for the argument) and C (for recursion). There is no other dependency in our IDTS. This means we can check off the second part of assumption (A.3) since > F is well-founded (it contains only

> F op, > F ap, > F λ, C > F op, C > F η and C > F λ). Assumption (A.4
) is trivial in our case since, within our IDTS, f = F g only when f = g. This assumption comes into play only in the general theory of IDTSs when one exploits mutual recursion with functions of multiple arguments. The stat f values mentioned in the assumption (A.4) describe the way in which a function's arguments should be ordered to guarantee that recursive calls are always made to smaller arguments. In the case of mutual recursion, both functions must agree on the order according to which they will decrease their arguments. Since we do not deal with mutual recursion in λ , we will not go into any more detail into this.

General Schema

There is one last obstacle in our way towards proving termination of λ τ . We will need to verify that the rewrite rules that we have given in Figure 3.1 follow the General Schema.

Definition 3.5.21. A rewrite rule

f (l 1 , . . . , l n ) → r follows the General Schema if r ∈ CC f (l 1 , . . . , l n ).
CC f (l 1 , . . . , l n ) refers to the so-called computable closure of the left-hand side f (l 1 , . . . , l n ). The idea behind the computable closure is that the left-hand side of a rewrite rule can tell us what are all the possible right-hand sides that still lead to a correct proof of termination. [START_REF] Simon | Haskell 98 language and libraries: the revised report[END_REF] A formal definition of computable closure is given in [19, p. 8].

Informally, r ∈ CC f (l 1 , . . . , l n ) if:

• Every metavariable used in r is accessible in one of l 1 , …, l n .

• Recursive function calls (i.e. uses of function symbols g = F f ) are made to arguments smaller than the arguments l 1 , …, l n .

A metavariable is accessible in a term if it appears at the top of the term or under abstractions or constructors. If a metavariable occurs inside an argument of a function symbol which is not a constructor, then there are some technical constraints on whether it is accessible. However, in every rewrite rule of our IDTS, the arguments of the function symbol being defined contain only constructors as function symbols.

Finally, we will need to show that the arguments being recursively passed to and C are smaller than the original arguments and therefore the recursion is well-founded and terminating. However, the General Schema presented in [19] uses a notion of "smaller than" which is not sufficient to capture the decrease of our arguments. On the other hand, when we were defining a denotational semantics for λ , we gave a well-founded ordering showing that the successive arguments to these operations are in fact decreasing. We will therefore make use of a technique which will allows us to incorporate this semantic insight into the IDTS so that the General Schema will be able to recognize the decreasing nature of the arguments.

Higher-Order Semantic Labelling

We will make use of the higher-order semantic labelling technique presented by Makoto Hamana in [55]. The idea behind the semantic labelling technique is to label function symbols with the denotations of their arguments. Whereas before, a function symbol was rewritten to the same function symbol on a smaller argument, in the labelled IDTS, a labelled symbol will be rewritten to a different smaller symbol (i.e. one with a smaller label).

The theory in [55] is expressed in terms of category theory. This results in a very elegant and concise formulation of the theorems and their proofs. In our thesis, we only care about the applications of the theory and so we will try to introduce the technique without presupposing the reader's familiarity with category theory.

Presheaves and Binding Algebras

We will nevertheless introduce a few terms from category theory.

When dealing with binding and types, it is usually not so useful to consider a mixed set of terms or denotations of different types. It is much more pertinent to speak of families of terms having the same type in the same typing context, i.e. T τ (Γ) = {t | Γ ⊢ t : τ }. In this example, T is a family of sets, indexed first by type and second by context. We can therefore say that T ∈ (Set F↓B ) B , where B is the set of base types of our IDTS (i.e. the set of λ types) and F ↓ B is the set of λ typing contexts (functions from finite sets to B).

The category-theoretical presentation of abstract syntax and binding originating in [45] relies on a similar notion known as presheaf. Presheaf can be seen as a synonym for functor (see 3.3.4), usually going from some kind of "index category" to some other category. In the above example, B, F ↓ B and Set can be seen as categories:

• B has base types as objects and no arrows besides the mandatory identities • F ↓ B has typing contexts as objects and renamings of contexts (exchanges, weakenings, contractions) as arrows

• Set is the standard category with sets as objects and functions as arrows Set F↓B is the category of functors from F ↓ B to Set. The object component of such a functor maps contexts to sets (usually sets of objects having some type within the given context). The arrow component translates the renamings of contexts into renamings of variables in these objects. The functors in the category (Set F↓B ) B map types to the objects of Set F↓B ; their arrow component is trivial since B has only trivial arrows.

We will call the objects of (Set F↓B ) B presheaves (sometimes, we will also call the objects in Set F↓B presheaves). In our presentation, we will care only about the object level, meaning that we will identify a presheaf with a family of sets. We will now consider some presheaves that will come into play:

• The key presheaf will be the presheaf

T of λ terms, T τ,Γ = {M | Γ ⊢ M : τ }. Every element of T τ,Γ is a well-typed λ term. • Another useful presheaf is the presheaf V of variables where V τ,Γ = {x | x : τ ∈ Γ}.
• Z is the presheaf of the IDTS metavariables from Z, Z τ,(x1:α1,...,xn:αn) = {M | M ∈ Z α1,...,αn,τ }.

• T Σ V is the presheaf of IDTS terms with alphabet Σ.

• M Σ Z is the presheaf of IDTS metaterms with alphabet Σ and typed metavariables Z. Now we will define some endofunctors on the category of presheaves. As before, we will ignore the arrow component and give only a mapping from one family to another.

• First, we introduce an endofunctor on the category of presheaves in Set F↓B . For every base type τ , we have a functor δ τ :

Set F↓B → Set F↓B . For A ∈ Set F↓B , we define (δ τ A)(Γ) = A(Γ + τ )
where Γ + τ is the extension of context Γ by a variable of type τ . [START_REF] Kammar | Handlers in action[END_REF] The idea behind this operation is to model binders, i.e. the arrow type ⇒ of IDTS. If the presheaf A β ∈ Set F↓B models the type β, then the presheaf δ α A β models the type α ⇒ β.

• The alphabet of our IDTS, Σ, induces an endofunctor on the category (Set F↓B ) B mapping presheaves

A to presheaves ΣA. (ΣA) γ = ⨿ f ∈F ⃗ α 1 ⇒β 1 ,..., ⃗ α l ⇒β l ,γ ∏ 1≤i≤l δ ⃗ αi A βi
In the above, we use the vector notation ⃗ α ⇒ β for α 1 ⇒ . . . ⇒ α n ⇒ β and δ ⃗ α for δ α1 • . . . • δ αn . Note that the above definition assumes that ⃗ α i , β i and γ are all base types. Since in our encoding of λ , we use a function constructor → on the level of base types, this is the case.

We are now ready to define the notion of a Σ-binding algebra.

Definition 3.5.22. A Σ-(binding) algebra

A is a pair of a presheaf A and a natural transformation64 α : ΣA → A. The presheaf is the carrier and the natural transformation interprets the operations. Since ΣA is a coproduct over all the f ∈ F, we can also see α as the copair

[f A ] f ∈F , where f A is the interpretation in algebra A of operation f .
We will need to construct a (V + Σ)-algebra in order to proceed, where (V + Σ)(A) is defined as V + Σ(A). Our algebra will be a term algebra, the carrier will be the presheaf T . We will need to give an interpretation to variables and to every function symbol defined in the alphabet Σ. This interpretation must be given as an α : V + ΣT → T , meaning that the interpretation of every function symbol must be compositional. A value from (ΣT ) γ,Γ is composed of some function symbol f of result type γ together with the interpretation of all of the symbol's arguments. If the i-th argument of the function symbol f has type β i and binds variables ⃗ alpha i , then the interpretation of the argument in our term model will be a λ term whose type in the context Γ + ⃗ α i is β i . The translation Term from λ τ terms to λ terms that we have given in 3.5.2 gives us the operations of the term model algebra. For example, the line defining the translation of the expression op(M p , [x]M c ) can be transformed into an interpretation for the function symbol op the following way:

Term(op(M p , [x]M c )) = op (Term(M p )) (λx. Term(M c )) op Γ (M p , M c ) = op (Term(M p )) (λx n+1 . Term(M c ))
where n = |Γ|. Therefore, the Term translation function from 3.5.2 gives us a (V + Σ)-algebra T with carrier T .

Building a Quasi-Model

We will now deal with presheaves equipped with partial orders.

Definition 3.5.23. A presheaf equipped with a partial order is a pair of a presheaf A and a family of partial orders ≥

A such that ≥ Aτ,Γ is a partial order on the set A τ,Γ .

Definition 3.5.24. An arrow

f : A 1 ו • •×A n → B in Set F↓B is weakly monotonic if for all Γ and a 1 , b 1 ∈ A 1 Γ , …, a n , b n ∈ A n Γ with a k ≥ A k,Γ b k for some k and a j = b j for all j ̸ = k, we have that f (Γ)(a 1 , . . . , a n ) ≥ BΓ f (Γ)(b 1 , . . . , b n ).
Definition 3.5.25. A weakly monotonic (V + Σ)-algebra is a (V + Σ)-algebra A whose carrier A is equipped with a partial order ≥ A such that every operation of A is weakly monotonic.

We want to equip our (V + Σ)-algebra T with the ↠ order. However, while we know that ↠ is by definition a preorder, reflexive and transitive, we do not know whether it is antisymmetric and therefore whether it forms a partial order. Because of this, we will build a partial order on top of the ↠ preorder. The interreducibility relation defined above is an equivalence relation and we can use it to quotient sets of terms. We define the T /⇄ presheaf as the presheaf with The preorder ↠ on λ terms can be extended to interreducibility classes of λ terms. Formally, we have M ↠ N if there exists M ∈ M and N ∈ N such that M ↠ N . This preorder is antisymmetric and the ↠ relation on interreducibility classes therefore forms a partial order. This means that (T /⇄ , ↠) is a presheaf equipped with a partial order.

T /⇄ τ,Γ = {{N | M ⇄ N } | Γ ⊢ M : τ }, i.e. T /
We can verify that ⇄ is a congruence on the (V + Σ)-algebra T . All of the operations in the algebra T construct new λ terms with the operands as subterms of the constructed term. Let f be an operation of T and M 1 , . . . , M k , and N 1 , . . . , N k be λ terms such that ∀i. M i ⇄ N i . Then we have

f (M 1 , . . . , M k ) ↠ f (N 1 , . . . , N k ) because ∀i. M i ↠ N i and f (N 1 , . . . , N k ) ↠ f (M 1 , . . . , M k ) because ∀i. N i ↠ M i . Therefore, we have f (M 1 , . . . , M k ) ⇄ f (N 1 , . . . , N k ).
Since ⇄ is a congruence on (V + Σ)algebra, we can quotient it and get a (V + Σ)-algebra T /⇄ whose carrier is the T /⇄ presheaf.

We now have a (V + Σ)-algebra, T /⇄ , whose carrier is equipped with a partial order, ↠. Because the reduction relation ↠ of λ is closed on contexts, the operations of T /⇄ are weakly monotonic: if we replace one of the arguments

M i in f (M 1 , . . . , M n ) with an M ′ i such that M i ↠ M ′ i , then we will also have f (M 1 , . . . , M i , . . . , M n ) ↠ f (M 1 , . . . , M ′ i , . . . , M n ).
Therefore, we have a weakly monotonic (V + Σ)-algebra T /⇄ . Definition 3.5.27. For a given (V + Σ)-algebra A, a term-generated assignment ϕ is an arrow in (Set F↓B ) B from the presheaf Z to the presheaf A such that ϕ = ! •θ, where:

• θ is an IDTS valuation, [START_REF] Kanazawa | Parsing and generation as datalog queries[END_REF] i.e. an arrow from Z to T Σ V .

• ! is the unique homomorphism from the initial (V + Σ)-algebra T Σ V to A. [START_REF] William R Keller | Nested cooper storage: The proper treatment of quantification in ordinary noun phrases[END_REF] To clarify the nomenclature: valuations replace metavariables with terms, assignments replace metavariables with interpretations in some algebra and term-generated assignments are assignments that can only assign an interpretation x if x can be computed as the interpretation of some term. Definition 3.5.28. A weakly monotonic (V + Σ)-algebra (A, ≥ A ) satisfies an IDTS rewrite rule l → r, with l and r of type τ , if for all term-generated assignments ϕ of the free metavariables Z in l and r, we have:

! θ * τ,Γ (l) ≥ Aτ,Γ ! θ * τ,Γ (r
) where ϕ = ! •θ, θ * is the extension of the valuation θ to meta-terms and Γ is the context regrouping all the free variables exposed by θ.

Chapter 3. Properties Definition 3.5.29. A weakly monotonic (V +Σ)-algebra (A, ≥

A ) is a quasi-model for the IDTS (Σ, R) if (A, ≥ A ) satisfies every rule in R.
Our weakly monotonic algebra (T /⇄ , ↠) is a quasi-model for the IDTS λ τ . The expressions L = ! θ * τ,Γ (l) and R = ! θ * τ,Γ (r) are instances of the left-hand and right-hand side, respectively, of the λ reduction rule l → r. Therefore, we always have L ↠ R.

Labelling Our System

We will now decide how to label the and C symbols. The labels we will choose will be the λ denotations introduced in 3.3.1. We will build up some orders on the denotations that will become crucial later. Definition 3.5.30. For each λ type τ , we define a well-founded strict partial order > τ on the set of denotations τ by induction on τ .

• τ is an atomic type Then > τ is the empty relation.

• τ = α → β f > τ g if
and only if f and g are both functions (i.e. not ⊥) and ∀x ∈ α . f (x) > β g(x). The new order is well-founded: any hypothetical descending chain

f 1 > τ f 2 > τ . . . could be projected to a descending chain f 1 (x) > β f 2 (x) > β . . ., which is well-founded by induction hypothesis. • τ = F E (γ) Let E = {op i : α i ↣ β i } i∈I .
The order > τ is the smallest transitive relation satisfying the following:

-∀i ∈ I, ∀p ∈ α i , ∀c ∈ F E (γ) βi , ∀x ∈ β i . op i (p, c) > τ c(x)
The proof of the well-foundedness of this relation was given in the definition of the interpretation of a handler (Definition 3.3.6). It relies on the fact that F E (γ) is defined as a union of an increasing sequence of sets where c(x) always belongs to a set preceding the one in which op i (p, c) appears for the first time.

As our labels, we will use denotations of (possibly open) λ terms. These objects are functions from Γ to τ for some typing context Γ and type τ . We will need to compare denotations of two objects having the same type but not necessarily occurring in the same typing context. We introduce some notation to deal with context and valuation extensions. Notation 3.5.31. Let Γ and ∆ be typing contexts. The typing context Γ, ∆, the extension of Γ with ∆, is defined by:

(Γ, ∆)(x) = { ∆(x), if ∆(x) is defined Γ(x), otherwise
Notation 3.5.32. Let e and d be valuations [START_REF] Kiselyov | Call-by-name linguistic side effects[END_REF] for the typing contexts Γ and ∆, respectively. The valuation e + d for the context Γ, ∆, called the extension of e with d, is defined by:

(e + d)(x) = { d(x), if x ∈ dom(d) e(x)
, otherwise Notation 3.5.33. We will use the term D(τ ) for the set ∪ Γ τ Γ , the set of possible denotations of τ -typed λ terms. Definition 3.5.34. Let τ be a λ type. The well-founded strict partial order > D(τ ) on the set D(τ ) is defined by: [START_REF] Kiselyov | Call-by-name linguistic side effects[END_REF] Not IDTS valuations, but the valuations used by the denotational semantics in 3.3.1.

Termination

77

• f > D(τ ) g if and only if:

-f : Γ → τ -g : Γ, ∆ → τ -∀e ∈ Γ , ∀d ∈ ∆ . f (e) > τ g(e + d)
We will use the notation ≥ D(τ ) for the reflexive closure of > D(τ ) .

For every symbol f to label, we will now choose a non-empty well-founded poset (S f , ≥ S f ), called the semantic label set. In our application of the technique, we will always choose the set of possible denotations of the argument that is being recursively decreased by the function. For the symbols that we do not care to label, we will assume that their semantic label set is the singleton set 1.

• For op 1 ,...,op n ,γ,δ,E,E ′ ∈ F α1→(β1→F E ′ (δ)),...,αn→(βn→F E ′ (δ)),γ→F E ′ (δ),FE (γ),F E ′ (δ)
, we take as the semantic label set the poset

D(F E (γ)) ordered by ≥ D(F E (γ)) . • For C α,β,E ∈ F α→F E (β),F E (α→β)
, we take as the semantic label set the poset

D(α → F E (β)) ordered by ≥ D(α→FE (β)) .
Having fixed the semantic label sets, we will now choose the semantic label maps. For each symbol

f ∈ F ⃗ α1⇒β1,..., ⃗
αn⇒βn,γ to be labelled, we define a weakly monotonic arrow ⟨⟨-⟩⟩ f in Set F↓B :

⟨⟨-⟩⟩ f : δ ⃗ α1 T /⇄ β1 × • • • × δ ⃗ αn T /⇄ βn -→ K S f where K A is the constant presheaf K A (Γ) = A.
This semantic label map has access to the interpretations of all of the function symbol's arguments and needs to map them to an element of the semantic label set. In our model, the carrier containing the interpretations is the presheaf T /⇄ of interreducibility classes of λ terms. However, the interreducibility relation ⇄ will be a congruence for all of the semantic label maps that we will define and so we will define them directly on terms instead of interreducibility classes.

This means that for every op 1 ,...,op n ,γ,δ,E,E ′ ∈ F α1→(β1→F E ′ (δ)),...,αn→(βn→F E ′ (δ)),γ→F E ′ (δ),FE (γ),F E ′ (δ) , we need to give:

⟨⟨-⟩⟩ : T α1→(β1→F E ′ (δ)) × • • • × T αn→(βn→F E ′ (δ)) × T γ→F E ′ (δ) × T FE (γ) -→ K D(FE (γ))
We do so by projecting the last argument, which is a λ term of type F E (γ) in the context Γ, and finding its denotation using -.

⟨⟨M 1 , • • • , M n , M η , N ⟩⟩ Γ = N
We will do the same for the C symbols. For every C α,β,E ∈ F α→FE (β),FE (α→β) , we give a:

⟨⟨-⟩⟩ C : T α→FE (β) → K D(α→FE (β)) by: ⟨⟨M ⟩⟩ C Γ = M
We can check that interreducibility is indeed a congruence for these semantic label maps: denotations are preserved under reduction (Property 3.3.8), and therefore all the terms in an interreducibility class have the same denotation. This means that we can extend these semantic label maps to T /⇄ , the carrier of our quasi-model (T /⇄ , ↠).

The semantic label maps must also be weakly monotonic. That is a condition that our maps satisfy: whenever we have M ↠ N , then by Property 3.3.8, the denotations M and N for M ∈ M and N ∈ N will be equal and therefore so will be the labels ⟨⟨M⟩⟩ and ⟨⟨N ⟩⟩. Since, ⟨⟨M⟩⟩ = ⟨⟨N ⟩⟩, we have ⟨⟨M⟩⟩ ≥ ⟨⟨N ⟩⟩.

We have now built up enough structure to correctly label our IDTS with denotations. Let us start with the alphabet. Definition 3.5.35. Let Σ = (B, X , F, Z) be the alphabet of an IDTS (Σ, R) and S f the chosen semantic label sets. The alphabet of the labelled IDTS (Σ, R) is the IDTS alphabet Σ = (B, X , F, Z) where:

• For every symbol f ∈ F α1,...,αn,β and for every label p in S f , we will have f p ∈ F α1,...,αn,β .

To complete our new IDTS, we will also have to transform the rules, so we will need a way to label metaterms. Definition 3.5.36. Let ϕ : Z → T /⇄ be a term-generated assignment with ϕ = ! •θ. The labelling map

ϕ L : M Σ Z → M Σ Z is the arrow in (Set F↓B ) B defined by: ϕ L τ,Γ (x) = x ϕ L τ,Γ (Z α1,...,αn,β (t 1 , . . . , t n )) = Z(ϕ L α1,Γ (t 1 ), . . . , ϕ L αn,Γ (t n )) ϕ L τ,Γ (f ([ ⃗ x 1 ]t 1 , . . . , [ ⃗ x n ]t n )) = f ⟨⟨! θ * (t1),...,! θ * (tn)⟩⟩ f Γ ([ ⃗ x 1 ]ϕ L βi,(Γ, ⃗ x1: ⃗ α1) (t 1 ), . . . , [ ⃗ x n ]ϕ L βn,(Γ, ⃗ xn: ⃗ αn) (t n )) where f ∈ F ⃗ α1⇒β1,..., ⃗ αn⇒βn,τ .
The labelling map traverses an IDTS metaterm and replaces unlabelled function symbols from F with labelled ones from F. Note that the term-generated assignment is not used to rewrite the metavariables: the assignment has values in the carrier presheaf of our (V + Σ)-algebra and it can therefore be something completely different than an IDTS term. The term-generated assignment ϕ = ! •θ is only used when labelling a function symbol. The IDTS valuation θ is used to replace the metavariables in all of the arguments with some specific terms and the resulting IDTS terms are then interpreted in our algebra T /⇄ using ! (which turns them into interreducibility classes of λ terms). These interpretations are then given as arguments to the semantic label map ⟨⟨-⟩⟩ f , which chooses a label from the label set. Note also that there is no case for bare abstraction ([x]t). In the theory of higher-order semantic labelling presented in [55], the IDTS is assumed to not contain any bare abstractions: abstractions should always be arguments to function symbols. This is the case in our IDTS λ τ .

Knowing how to label metaterms, we can now label the rules of an IDTS.

Definition 3.5.37. Given an IDTS (Σ, R), a (V + Σ)-algebra M and a choice of semantic label sets S f and maps ⟨⟨-⟩⟩ f , we define the rules of the labelled IDTS (Σ, R) with:

• R = {ϕ L τ,∅ (l) → ϕ L τ,∅ | l → r : τ ∈ R, term-generated assignment ϕ : Z → M }
The labelled IDTS will multiply the number of rules. For every possible IDTS valuation of the free metavariables of a rule, there will be a new rule in which the function symbols have been labelled using the interpretations of their arguments. As we have done in 3.5.2, we will have to show that termination of this new labelled system gives us termination of the unlabelled one. This is the object of the principal result in [55] (Theorem 3.7):

Theorem 3.5.38. Higher-order semantic labelling

Let M be a quasi-model for an IDTS (Σ, R) and (Σ, R) the labelled IDTS with respect to M . Then (Σ, R) is terminating if and only if (Σ, R ∪ Decr) is terminating. Definition 3.5.39. Given a labelled IDTS alphabet Σ with semantic label sets S f , the rules of the IDTS (Σ, Decr) (called decreasing rules) consist of:

f p ([ ⃗ x 1 ]t 1 , . . . , [ ⃗ x n ]t n ) -→ f q ([ ⃗ x 1 ]t 1 , . . . , [ ⃗ x n ]t n )
where f ∈ F ⃗ α1⇒β1,..., ⃗ αn⇒βn,γ and p > S f q. The decreasing rules allow us to freely adjust the labels on function symbols to fit rewrite rules as long as we do not increase them.

Verifying the General Schema

Now we will retrace the steps we have carried out in 3.5.3, this time with our semantically labelled system λ τ .

1. every constructor is positive 2. no left-hand side of rule is headed by a constructor 3. both > B and > F are well-founded 4. stat f = stat g whenever f = F g First we have to check off the assumptions (A.1) through (A.4), repeated above. The constructors of λ τ are the same as the ones in λ τ and so we validate assumption (A.2). It also means that the induced ordering > B is the same as before and it is therefore still well-founded, so we have the first half of assumption (A.3). Since > B is still the same, then so is = B , which is used in the definition of positive constructors (Definition 3.5.18). The constructors are therefore still positive as well and we get assumption (A.1).

To verify the second half of assumption (A.3) and assumption (A.4), we will need to investigate the ordering on function symbols > F and it is here that we will reap the benefits of our labelling. We need to give a well-founded partial order ≥ F on the function symbols such that whenever we have a rule f (l 1 , . . . , l n ) → r, then f ≥ F g for all function symbols g occurring in r. We propose the following relation:68

• p op 1 ,...,op n ,γ,δ,E,E ′ > F q op 1 ,...,op n ,γ,δ,E,E ′ if p > S q • op 1 ,...,op n > F op i • > F ap • > F λ • C p α,β,E > F C q α,β,E if p > SC q • C > F op • C > F η • C > F λ
Whenever we elide indices in the above (for labels, types or the operations in a handler), we assume that they are universally quantified over. This relation is indeed a well-founded strict partial order: ap, op, η and -• are minimal elements and decreasing chains of or C symbols are all finite since the underlying semantic label set orderings > S f are well-founded. This means that our > F ordering validates the second half of assumption (A.3). We also let ≥ F be the reflexive closure of > F and then we validate assumption (A.4) because f = F g only if f = g.

We have checked off all of the assumptions and so now we need to check whether the rewrite rules of our labelled IDTS λ τ all follow the General Schema. This boils down to checking whether the ≥ F order correctly describes the recursive behavior of our function definitions. Whenever we use a function symbol g in the right-hand side r of a rule f (l 1 , . . . , l n ) → r, we need to show that f ≥ F g. Furthermore, if f = F g, we need to show that the arguments passed to g are smaller than the arguments l 1 , . . . , l n passed to f . However, thanks to the semantic labelling, we will be able to show that for every rule f (l 1 , . . . , l n ) → r, f > F g for any function symbol g occurring in r.

We first check the rules in Decr. These work out because > F contains the label ordering for both labelled function symbols, and C (i.e. p > F q and C p > F C q whenever p > q).

p (M i . . . , M η , N ) → q (M i . . . , M η , N ) C p (M ) → C q (M ) whenever p > q
Then we check the rules that correspond to reductions in λ , looking at either the original formulation on Figure 1.4 or the CRS/IDTS versions on Figure 3.1. For most of the rules, it is just a matter of checking that only certain symbols appear in the right-hand sides of certain rules. However, in rules op , op ′ and C op , we have the same (unlabelled) symbol on both the left-hand side and the right-hand side of the rule. In these cases, we will need to prove that the label on the right-hand side occurrence is strictly smaller than the label on the left-hand side occurrence.

We will start with the rules op and op ′ .

(op i : M i ) i∈I , η: M η p (op j N p (λx. N c )) → M j N p (λx. (op i : M i ) i∈I , η: M η q N c ) where j ∈ I (op i : M i ) i∈I , η: M η p (op j N p (λx. N c )) → op j N p (λx. (op i : M i ) i∈I , η: M η q N c ) where j / ∈ I
In both cases, the on the left-hand side is applied to Γ ⊢ op j N p (λx. N c ) : F E (γ) whereas the on the right-hand side is applied to Γ, x : β j ⊢ N c : F E (γ) where op j : α j ↣ β j ∈ E. The label p of the left will be the denotation op j N p (λx. N c ) whereas the label q of the right will be the denotation

N c .
The ordering on these labels is the > D(FE (γ)) ordering. For the first to be greater than the second, we will need to prove for all e ∈ Γ and all d ∈ β j that op j N p (λx.

N c ) (e) > FE (γ) N c (e[x := d]). op j N p (λx. N c ) (e) = op j ( N p (e), λX. ( N c (e[x := X])))
From the definition of > FE (γ) (Definition 3.5.30), we know that for all d ∈ β j , op j ( N p (e), (λX. Having shown that the function symbols that head the left-hand sides of rules are strictly larger (in a well-founded poset) than the function symbols that occur in the right-hand sides gives us termination for the labelled IDTS λ τ via Theorem 3.5.12.

Theorem 3.5.40. (Termination of λ τ )

The reduction relation induced by the labelled IDTS λ τ is terminating. [START_REF] Kiselyov | Applicative abstract categorial grammars in full swing[END_REF] Proof. Proof given above by the application of the General Schema presented in [19].

Putting η Back in λ

We have shown termination for λ -η . We know that the η-reduction on λ is terminating: it decreases the number of λ-abstractions in the term by one in each step. We would now like to show that the combination of λ -η and η is terminating as well. Note that we could not have used the General Schema to prove that λ with η is terminating. The General Schema does not admit η-reduction. The left-hand side of every rule needs to be headed by a function symbol which is not a contructor. If we tried declaring that λ is not a constructor, we would run into problems with the notion of accessibility. When accessing the metavariables of the left-hand side of a rule, we can access all of the arguments of a constructor but we can only access the arguments of a non-constructor symbol that has a basic type. The type of the argument of λ α,β is α ⇒ β and so we could not access the arguments of λ in our rules (which would break the β rule, η rule and the C rules).

Termination is generally not a modular property of higher-order rewriting systems [7]. Our plan will be to show that η-reduction does not interfere with the rewrite rules of λ -η . Then we will be able to take any reduction chain in λ and pull out from it a chain which only uses rules from λ -η . Since this chain must be finite due to the termination of λ -η , we will have a proof of finiteness for the reduction chain in λ . For every well-typed reduction chain s → η t → λ -η u, there exists a well-typed reduction chain s → + λ -η t ′ → * η u. Proof. We will consider all the possible relative positions of the contractum of the first reduction and the redex for the second reduction within t.

• Assume the two are disjoint, i.e. s = C[M, N ], t = C[M ′ , N ] with M → η M ′ and u = C[M ′ , N ′ ] with N → λ -η N ′ .
Then we can easily reorder the two reductions, producing the chain

C[M, N ] → λ -η C[M, N ′ ] → η C[M ′ , N ′ ].
• Assume that the contractum of the first reduction contains the redex for the second reduction, i.e.

s = C[M ], t = C[D[N ]] with M → η D[N ] and u = C[D[N ′ ]] with N → λ -η N ′ . Since M is an η-redex, M = λx. D[N ] x. We can now build the chain C[λx. D[N ] x] → λ -η C[λx. D[N ′ ] x] → η C[D[N ′ ]].
• Assume that the redex for the second reduction contains the contractum of the first reduction, i.e.

s = C[D[M ]], t = C[D[M ′ ]] with M → η M ′ and u = C[N ′ ] with D[M ′ ] → λ -η N ′ . Let R be the rule used in D[M ′ ] → λ -η N .
We will now distinguish two scenarios:

-The occurrence of M ′ in D[M ′ ] is matched by a metavariable in the left-hand side of rule R. The R-redex N ′ of D[M ′ ] will be a term E n [M ′ , . . . , M ′
] where E n is an n-ary context for some n which depends on the rule R and the metavariable that was matched. [START_REF] Kiselyov | Freer monads, more extensible effects[END_REF] Furthermore, we can replace M ′ with any other term of the same type and the reduction will still go through, e.g. notably

D[M ] → R E n [M, . . . , M ]. We can now build our chain C[D[M ]] → λ -η C[E n [M, . . . , M ]] → * η C[E n [M ′ , . . . , M ′ ]] = C[N ′ ]. -The occurrence of M ′ in D[M ′ ] is not matched by a metavariable.
M ′ is an η-contractum and must therefore have a function type. If we investigate the left-hand sides of all the rewriting rules in λ -η and search for terms that have a function type, we end up with:71

* D = [] N and R = β * D = C [] and R = C op or R = C η
We note that in all of these rules, the symbol which replaces [] must be a λ-abstraction. Therefore, if

D[M ′ ] → R N , then M ′ = λx. M ′′ . From M → η M ′ , we also know that M = λx. M ′ x.
We can replace this step by a β-reduction: M = λx. (λx. M ′′ ) x → β λx. M ′′ = M ′ . The β rule is a part of λ -η and so we can now build the chain

C[D[M ]] → λ -η C[D[M ′ ]] → λ -η C[N ′ ].

Lemma 3.5.45. Pulling a λ -η link from a λ chain

Let t 1 → t 2 → . . . be an infinite reduction chain in λ . Then there exists another infinite reduction chain

u 1 → u 2 → . . . in λ and t 1 → λ -η u 1 .
Proof. The goal of this lemma is to show that we can find an λ -η link in every infinite λ and move it to the beginning of the chain. An infinite chain in λ must use a rule from λ -η , otherwise it would be an η chain and those cannot be infinite since η is terminating.

Let t k → t k+1 be the first link in the chain that uses a rule from λ -η . We will prove this lemma by induction on k.

If k = 1, then we can use the chain t 2 → t 3 → . . . which also uses rules from λ -η infinitely often and which satisfies t 1 → λ -η t 2 .

If k > 1, then we replace the segment t k-1 → η t k → λ -η t k+1 with the segment t k-1 → + λ -η t k → * η t k+1 using Lemma 3.5.44. By induction hypothesis, the chain

t 1 → . . . → t k-1 → + λ -η t k → * η t k+1 → t k+2 → . . . gives us the necessary chain u 1 → u 2 → . . . with t 1 → λ -η u 1 .

Theorem 3.5.46. Termination of λ

The reduction relation → on λ terms given by the rules in Figure 1.4 is terminating.

Proof. We will prove this theorem by contradiction. Let t 1 → t 2 → . . . be an infinite reduction chain in λ . Since we have an infinite chain in λ , we can iterate Lemma 3.5.45 to get an infinite sequence of chains such that the first element of every chain reduces via λ -η to the first element of the next chain in the sequence. The first elements of these chains form an infinite reduction chain λ -η , which is in contradiction with the termination of λ -η .

Theorem 3.5.47. Strong normalization of λ

There are no infinite reduction chains in λ and all maximal reduction chains originating in a λ term M terminate in the same term, the normal form of M .

Continuations

Continuations are a fundamental notion in computer science. They subsume all of the monadic structures that we are interested in [44] and they are central to the meaning of linguistic expressions [14]. In this chapter, we will show the connection between calculi containing operators for manipulating continuations and our λ calculus. Throughout the chapter, we will introduce different calculi and map their terms and reduction relations onto the terms and reduction relation of λ . For one of the calculi with control operators, we also introduce a type system, which is a simplification of the one found in [33] and we map it onto the type system of λ . See Figure 4.1 for a high-level look at the structure of the chapter.

. . λ v (4.1)
.

λ shift (4.5)
.

λ shift0 (4.3) . λ (1) . (4.2) .

Introducing Call-by-Value

The nature of control operators is that their evaluation depends on their context. In order for a language with such control operators to be deterministic, it must have a fixed evaluation order. So in order to set up the stage for our study of delimited control, we will start by simulating the call-by-value λ-calculus in λ .

First, we introduce some key notions of call-by-value and ordered evaluation in the call-by-value λcalculus.

We will single out some of the terms in λ v and call them values.

Definition 4.1.1. The following grammar defines the terms of λ v (metavariables M and N ) and the values (metavariable V ).

V ::= λx. M | x M, N ::= V | (M N )
The idea behind this distinction is that values (V ) are terms that have already been reduced/evaluated. This distinction will become useful in definining the following notion: Definition 4.1.2. We define an evaluation context C as a structure formed by the following grammar:

C ::= [] | (C M ) | (V C)
We write C[M ] to designate the term that you obtain by replacing the [] in C with M .

We now have all the pieces in play to be able to define the semantics of λ v .

Definition 4.1.3. A term M reduces to a term N in one step, written as M → N , when the pair M → N matches this pattern:

C[(λx. M ) V ] → β C[M [x := V ]]
Here we see that we only substitute values for the variables in a λ-abstraction. Also note that we can only perform reductions inside an evaluation context. Given our definition of C, this enforces a left-toright evaluation order and also prohibits evaluation under a λ-abstraction.

Simulating Call-by-Value

We first present the translation from λ v to λ and then we elaborate on it. Definition 4.2.1. Let M be a term of λ v . We define its interpretation in λ , written as M :

x = η x λx. M = η (λx. M ) M N = M ≫= (λm. N ≫= (λn. m n))

Simulating Call-by-Value

87

An expression of λ v is modelled in λ as a computation. The values form a special case since they are all interpreted as pure computations, terms of the form (η M ) for some M . In interpreting an application (M N ), we first evaluate M and then N , reflecting the behavior we have defined for λ v above.

Before we show that this translation is indeed a faithful one, we will discuss the types of the interpretations to get a better understanding of the structures involved. λ v can be typed with the type system of the simply-typed λ-calculus. A well-typed λ v term will then yield a well-typed λ term since our translation satisifies the following property. Property 4.2.2. Let M be λ v term, α a simple type, Γ a simply-typed environment and E an effect signature. Then the following implication holds.

Γ ⊢ M : α ⇒ Γ ⊢ M : F E ( α )
Proof. By structural induction on the structure of M . The Definition 4.2.3 of . for simple types and simply-typed environments is given just below.

Definition 4.2.3. We define the interpretation of types and environments using the following formulas. ν stands for an atomic type and ∅ for the empty environment.

α → β = α → F E ( β ) ν = ν Γ, x : α = Γ , x : α ∅ = ∅
We see that we model λ v expressions of type α using computations that yield values of type α .

. translates the function type so that it takes values but produces computations (since the body of a λ-abstraction can in general be any expression and the denotation of an expression is a computation).

To show that our translation simulates the behavior of λ v , we will prove that any reduction chain M ↠ N in λ v gives rise to a reduction chain M ↠ N in λ . We start by proving

(λx. M ) V ↠ M [x := V ] .
Property 4.2.4. Let M be a λ v term and V a λ v value. Then the following reduction chain exists in λ :

(λx. M ) V ↠ M [x := V ] Proof. (λx. M ) V = λx. M ≫= (λm. V ≫= (λn. m n)) (1)
= (η (λx. M )) ≫= (λm. (η v) ≫= (λn. m n)) (2)
→ η.≫=,β (η v) ≫= (λn. (λx. M ) n) (3)
→ η.≫=,β (λx. M ) v (4)
→ β M [x := v] (5) = M [x := V ] (6)
where V = η v. We first expand the definition of . for the application, the abstraction and the argument value (we note that V is always equal to η v for some v). Since we have two occurrences of a pure computation being piped into a bind ((η x) ≫= k), we can simplify using η.≫= and β. On line 5, we finally get to the point where we perform the λ β-reduction that actually corresponds to the λ v β-reduction that we are modelling.

On line 6, we push the substitution under the . operator. This is valid, since any free x in M must have originated as a translation of a free x in M . In the first expression, such an x would get interpreted as η x and then x would get replaced with v to get η v. In the second expression, the x would first get replaced by V and then V would be interpreted as η v. In both cases, we get the same result.

We have proven that our simulation preserves the reduction (λx. M ) V → M [x := V ]. However, it might seem that our work is not over since this is just a special case of the rule in λ v , which licenses the reduction C

[(λx. M ) V ] → C[M [x := V ]].
Nevertheless, our calculus is pure and lets us perform reductions in any syntactic context (see the notion of context closure from 1.4). This means that whenever we have M → N , we also always have [START_REF] Kiselyov | Lambda: the ultimate syntax-semantics interface[END_REF] which is the same as We have shown that our translation preserves reduction chains. Can we get anything stronger?

C [ M ] → C [ N ],
C[M ] → C[N ] .
The inverse is not true in this case. Consider the example of M = λx. ((λy. y) x) and N = λx. x. If we take M and perform some reductions, we arrive at η (λx. η x). However, this is equal to N and so we have M ↠ N . This is the case even though M does not reduce to N in λ v (λ v does not allow reductions inside a λ-abstraction). Our interpretation will end up licencing an equality between M and N even though the language we were modelling (λ v ) does not equate them (in a way, this interpretation is complete but not sound). While this makes the interpretation less appealing, we still elaborate it because it is instructive in showing the similarity between delimited control and effect handlers.

To conclude this section, we have defined a translation from λ v to λ and proven that it preserves types and reductions. This means that we have a way of simulating simply-typed λ v in our typed λ and a way of simulating untyped λ v in an untyped version of λ .

Introducing Control Operators

Now that we have introduced how a λ-calculus with a notion of evaluation order is to be interpreted in λ , we are ready to introduce control operators. Our claim is that the effects and handlers of λ are very close to delimited continuations. [START_REF] Kiselyov | Eff directly in ocaml[END_REF] The pair of operators that resembles the behavior of handlers the most are the operators shift0 and reset0. Definition 4.3.1. We define the terms (M , N ) and values V of λ shift0 using the following grammar:

V ::= λx. M | x M, N ::= V | (M N ) | (shift0 M ) | (reset0 M )
The terms of this new calculus, λ shift0 , are just the terms of λ v extended with the operators shift0 and reset0. Before we give the reduction rules, we will also have to refine our notion of an evaluation context.

Definition 4.3.2. We define evaluation contexts (C) and evaluation frames (F ) the following way:

C ::= [] | (C M ) | (V C) | (shift0 C) | (reset0 C) F ::= [] | (F M ) | (V F ) | (shift0 F )
For evaluation contexts (C), we add rules saying that when evaluating applications of either shift0 or reset0, we can evaluate their arguments. We also introduce a notion of an evaluation frame (F ). Similarly to how values are a subset of terms, evaluation frames are a subset of evaluation contexts. A frame is a context which does not embed [] inside a reset0.

C[(λx. M ) V ] → β C[M [x := V ]] C[reset0 V ] → reset0 C[V ] C[reset0 (F [shift0 V ])] → shift0 C[V (λx. reset0 (F [x]))]
We keep the reduction rule β and we add two new rules for reset0 and shift0. The rule for reset0 makes reset0 look redundant but its importance shows up in the rule for shift0. In the shift0 rule, we have an application of shift0 buried inside the context C[reset0 F ]. This kind of context corresponds to a context which embeds [] inside at least one reset0. The F then corresponds to the frame which separates the shift0 from the nearest enclosing reset0. The only role of reset0 is thus to serve as a kind of marker to delimit the context/continuation F of shift0. The argument to shift0 then receives this continuation F , composed with reset0, as its argument. [START_REF] Cole | Introduction to metamathematics[END_REF]

Simulating shift0 and reset0

To simulate λ shift0 in λ , all we have to do is extend the simulation of λ v with interpretations of the two new syntactic forms. Definition 4.4.1. Let M be a term of λ shift0 . We define its interpretation M as an extension of the interpretation defined for λ v with the following clauses:

shift0 M = M ≫= (λm. shift0! m) reset0 M = shift0: (λck. c k) M
The above translation also gives us a general template for simulating effectful calculi in λ . Amongst the impure operators of a calculus, we identify those that manipulate a context (raising an exception, modifying a variable, reading a dynamically bound value, accessing the continuation…) and those that establish a context (exception handlers, transactions, binders for dynamic variables, continuation delimiters such as prompt or reset…). Operators that manipulate the context are translated into operations in λ , i.e. op M = M ≫= (λm. op! m). Operators that establish a context are translated into handlers, i.e. op M = . . . M .

Chapter 4. Continuations

To show that this simulation is faithful, we will prove that M → N in λ shift0 implies M ↞ ↠ N in λ . M ↞ ↠ N says that we can go from M to N through a series of reductions and expansions, i.e. M and N are convertible. [START_REF] Willem | Term rewriting systems[END_REF] In this case, our simulation property will prove that equivalence given by the calculus' equational theory is preserved, i.e. M = N in λ shift0 implies M = N in λ (where Proof. We have three reduction rules to tackle: → β , → reset0 and → shift0 . We have proven the case of → β in 4.2 and that proof still holds in this extended interpretation. We also reuse our observation from 4.2 that in order to prove

X = Y is to be read as X ↞ ↠ Y ).
C[M ] ↠ C[N ]
, it is enough to prove M ↠ N . The case of → reset0 is a simple one so we will deal with that first:

reset0 V = shift0: (λck. c k) V (1)
= shift0: (λck. c k) (η v) (2)
→ η η v (3) = V (4)
where V = η v. As we have said in 1.6.2, an (open) handler without an explicit clause for η is presumed to handle η with η. In this case, the λ shift0 reduction ends up corresponding to exactly one η reduction in λ . Now, let's deal with the last reduction rule, → shift0 .

reset0 (F [shift0 V ]) = shift0: (λck. c k) F [shift0 V ] (1)
↞ ↠ shift0: (λck. c k) (shift0 v (λx. F [x] )) (2)
→ op (λck. c k) v (λx. shift0:

(λck. c k) F [x] ) (3)
→ β,β v (λx. shift0: (λck. c k) F [x] ) (4) = v (λx. reset0 (F [x]) ) (5)
← β,η.≫= (η (λx. reset0 (F [x]) )) ≫= (λn. v n) (6) = λx. reset0 (F [x]) ≫= (λn. v n) (7) ← β,η.≫= (η v) ≫= (λm. λx. reset0 (F [x]) ≫= (λn. m n)) (8)
= V ≫= (λm. λx. reset0 (F [x]) ≫= (λn. m n)) (9) = V (λx. reset0 (F [x])) (10)
where V = η v. Lines 2 and 3 are the crucial lines. On line 2, we use the upcoming Lemma 4.4.4 that will show that through a series of reductions and expansions, we can go from

F [shift0 V ] to (shift0 v (λx. F [x]
)) where V = η v. Since we have moved shift0 to the head of the handler's argument, we can apply the op rule on line 3. Since the handler clause is basically the identity function, it disappears on line 4 after two β-reductions.

From then on, we perform a series of expansions while trying to push the interpretation operator . outwards from F [x] to the entire expression. The expansions used above are a reversal of a common idiom we have used before. We used to go from (η M ) ≫= (λm. N ) to N [m := M ] using η.≫= and then a β-reduction. Here, we go the other way from N [m := M ] to (η M ) ≫= (λm. N ) using a β-expansion and the derived expansion η.≫= (lines 6 and 8).

Contexts = Continuations: Proving the Lemma

All that is left to show is a proof of the lemma we mentioned above. Lemma 4.4.4.

F [shift0 V ] ↞ ↠ (shift0 v (λx. F [x] )) where V = η v.
This lemma not only allows us to prove the simulation property that is the focus of this section, but it also gives us more insight into λ . If we read it from right to left and slightly generalizing, it tells us how to think of terms of the form (op x k). They represent computations where the next point of evaluation is a contextually dependent operation op: x is the operation's argument and k captures the context in which op is being used inside the computation.

Proof. Our proof will proceed by induction on the structure of F . We will start with the base case, F = [].

F [shift0 V ] = shift0 V (1) = V ≫= (λm. shift0! m) (2)
→ η.≫=,β shift0! v (3) = (λp. shift0 p (λx. η x) v (4)
→ β shift0 v (λx. η x) (5) = shift0 v (λx. x ) (6)
= shift0 v (λx. F [x] ) (7)
The individual steps are pretty self-explanatory. On line 4, we expand the definition of the exclamation mark from 1.6.2.

Next case, F = (F ′ M ):

F [shift0 V ] = (F ′ [shift0 V ]) M (1) = F ′ [shift0 V ] ≫= (λm. M ≫= (λn. m n)) (2)
↞ ↠ (shift0 v (λx. F ′ [x] )) ≫= (λm. M ≫= (λn. m n)) (3)
→ op.≫= shift0 v (λx. F ′ [x] ≫= (λm. M ≫= (λn. m n))) (4)
= shift0 v (λx. (F ′ [x]) M ) (5) = shift0 v (λx. F [x] ) (6) (7)
Again, the steps are quite mechanical. Line 3 uses the induction hypothesis and on line 4, we see the derived op.≫= rule introduced in 3.1.2 pushing the ≫= inside the continuation.

Case F = (V ′ F ′ ):

F [shift0 V ] = V ′ (F ′ [shift0 V ]) (1)
= V ′ ≫= (λm. F ′ [shift0 V ] ≫= (λn. m n)) (2)
→ η.≫=,β F ′ [shift0 V ] ≫= (λn. v ′ n) (3) ↞ ↠ (shift0 v (λx. F ′ [x] )) ≫= (λn. v ′ n) (4) → op.≫= shift0 v (λx. F ′ [x] ≫= (λn. v ′ n)) (5)
← β,η.≫= shift0 v (λx. V ′ ≫= (λm. F ′ [x] ≫= (λn. m n))) (6) = shift0 v (λx. V ′ (F ′ [x]) ) (7)
= shift0 v (λx. F [x] ) (8)
where V ′ = η v ′ . This proof is very similar to the one for the case before. We have just two extra steps, on lines 3 and 6, where we first push the V ′ (= η v ′ ) in through the ≫= using η.≫= and β and then we pull it out in a different context by reversing the process.

Finally, the last case, where F = (shift0 F ′ ):

F [shift0 V ] = shift0 (F ′ [shift0 V ]) (1)
= F ′ [shift0 V ] ≫= (λm. shift0! m) (2)
↞ ↠ (shift0 v (λx. F ′ [x] )) ≫= (λm. shift0! m) (3)
→ op.≫= shift0 v (λx. F ′ [x] ≫= (λm. shift0! m)) (4)
= shift0 v (λx. shift0 (F ′ [x]) ) (5)
= shift0 v (λx. F [x] ) (6)
And this case is just as simple as the F = (F ′ M ) one. This concludes our proof of this lemma. Note that we did not include a case for F = (reset0 F ′ ). Such a context is not a frame, since it embeds [] inside a reset0. We can also check that our property would no longer hold in this case, since the shift0 coming from F ′ would get handled by the reset0.

By proving this lemma, we have also finished our proof of the fact that whenever we have M ↞ ↠ N in λ shift0 , we also have M ↞ ↠ N in λ .

Turning to shift and reset

There are other control operators, similar to shift0 and reset0. One example would be the more common shift and reset. The difference between these two pairs can be appreciated by comparing the reduction rules for shift0 and shift.

C[reset0 (F [shift0 V ])] → shift0 C[V (λx. reset0 (F [x]))] C[reset (F [shift V ])] → shift C[reset (V (λx. reset (F [x])))]
shift preserves the delimiting reset and installs a new one into the continuation. shift0 is different in that it removes the delimiting reset0. In all other ways, the definition of λ shift (the call-by-value λcalculus equipped with shift and reset) is identical to the one of λ shift0 .

We have seen that the semantics of shift0 and reset0 aligns closely with the behavior of operations and handlers in λ . However, we can translate shift and reset to λ too.

We will do so by first translating λ shift to λ shift0 .

Definition 4.5.1. The interpretation M 0 of a λ shift term M into λ shift0 is defined as follows:

reset M 0 = reset0 M 0 shift M 0 = shift0 ((λm. λk. reset0 (m k)) M 0 ) M N 0 = M 0 N 0 λx. M 0 = λx. M 0 x 0 = x NB: We cannot use (shift0 (λk. reset0 ( M 0 k))) for the interpretation of shift M . That would result in (shift []) 0 being equal to (shift0 (λk. reset0 ([] k))).
The problem here is that (shift []) is an evaluation frame in λ shift , but its interpretation is not even an evaluation context in λ shift0 since the [] is buried under a λ-abstraction.

To see that this interpretation preserves the same kind of property we have been demonstrating in the rest of this section, we prove the following. Proof. We first note that if C is an evaluation context in λ shift , C 0 (where . 0 has been extended to contexts with [] 0 = []) is an evaluation context in λ shift0 . The same also holds for evaluation frames and values. With these observations in our hand, we can proceed onto the proof.

We consider the three possible cases of M → N that correspond to the three reduction rules in λ shift . Since the rules → β and → reset /→ reset0 are identical in both calculi and since . 0 preserves evaluation contexts and values, these cases fall out immediately.

We only have to handle the interesting case of M → shift N . In that case,

M = C[reset (F [shift V ])] and N = C[reset (V (λx. reset (F [x])
))] for some context C, frame F and value V .

M 0 = C[reset (F [shift V ])] 0 (1) = C ′ [reset0 (F ′ [shift0 ((λm. λk. reset0 (m k)) V ′ )])] (2)
→ β C ′ [reset0 (F ′ [shift0 (λk. reset0 (V ′ k))])] (3)
→ shift0 C ′ [(λk. reset0 (V ′ k)) (λy. reset0 (F ′ [y]))] (4)
→ β C ′ [reset0 (V ′ (λy. reset0 (F ′ [y])))] (5) = C[reset (V (λx. reset (F [x])))] 0 (6) = N 0 (7)
where For the latter corollary, we just compose the translations from λ shift to λ shift0 and from λ shift0 to λ and transitively apply their simulation properties (Corollaries 4.4.3 and 4.5.3). This lets us extend our interpretation . to λ shift .

C ′ = C 0 , F ′ = F 0 and V ′ = V 0 .
shift M = M ≫= (λm. shift0! (λk. shift0:

(λck. c k) (m k))) reset M = shift0: (λck. c k) M
In the sequel, we will be translating a type system of λ shift to the type system of λ . For the types to work out in this translation, we will need to throw a few bananas into the mix. In what will follow, we will assume that shift and reset are translated to λ using the interpretations given below:

shift M = M ≫= (λm. shift0! (λk. shift0: (λck. c k) (m ( • k)))) reset M = ( shift0: (λck. c k) M )
is actually a valid handler. As any other handler without an explicit clause for η, it handles η with η. It also handles all operations with the operations themselves (i.e. rule op ′ ). It is therefore an identity function on computations. However, the most general type that we can infer for is F E (α) → F E ′ (α) for any E and E ′ such that E ⊆ E ′ . It can therefore be used as a kind of explicit weakening operator on computation types. [START_REF] Klop | Combinatory reduction systems: introduction and survey[END_REF]

Considering Types

We have shown embeddings of λ shift0 and λ shift into λ . In both of these embeddings, we have seen that the reduction rules in λ can emulate those of λ shift and λ shift0 . However, we have not defined λ only via terms and their reductions, we have also specified a type system. Can we somehow guarantee that the results of interpreting λ shift into λ are well-typed?

Clearly not without having some kind of type system for λ shift . Without a type system, we can write a term like λx. x x whose translation to λ is impossible to type. Danvy and Filinski [33] give a type system for a calculus with shift and reset. In their system, typing judgments have the following form:

ρ, α ⊢ E : τ, β
In this schema, ρ stands for a type environment (context Γ in our notation), E is an expression (a term) and τ is the type of E. The types α and β describe the context in which the expression can occur. If we rewrote E in continuation-passing style, we would get a term of type (τ → α) → β. The expression E can access a context whose answer type is α and supplant it by an answer of type β.

This kind of type system allows us to write a computation that performs a series of shifts, each one changing the answer type for the next. If we wanted to guarantee type safety while allowing this amount of flexibility, we would need to use indexed effects [6] to track the answer type as it changes from shift0 to shift0. We will therefore modify Danvy and Filinski's type system to prohibit continuations from changing the answer type so as to fit into the capabilities of our type system. Our modified type system will have judgments that follow this schema:

Γ | γ ⊢ M : τ We switch to our style of notation, Γ is a typing context and M is a term. We give only a single answer type, γ, written to the left of the turnstile. We also separate it from the type context with a vertical bar instead of a comma so as not to be confusing with the notation for context extension (Γ, x : α). In continuation-passing style, the type of the above term M would correspond to (τ → γ) → γ.

There is one more subtlety to cover before we look at the typing rules themselves: what are the types? Since the well-typedness of an expression depends on the context in which it is being evaluated, the function type becomes a bit more complicated. By embedding an expression inside a λ-abstraction, we delay its evaluation. In function application, the context of the application becomes the context the function body. In other words, if when type checking the body of a function we assume that the current answer type is γ, then when we apply this function to an argument, we should better do so in a context in which the answer type actually is γ. This means we have to discriminate between functions w.r.t. the context (i.e. answer type) in which they can be applied. Definition 4.6.2. We define the typing relation for λ shift as the set of all judgments derivable from the inference rules given in Figure 4.2.

To convince ourselves that this type system works, we will need to prove its soundess by way of demonstrating type preservation and progress. Proof. This technical lemma, common to most λ-calculi, is proven by induction on the derivation of Γ, x : α | γ ⊢ M : τ (which is the same as induction on the syntactic structure of M ). The only catch here is that when we descend into M through λ-abstractions and resets, we might be forced to change the answer type from γ to some δ. Now, in order for the induction to work, we will need to change the answer type in Γ | γ ⊢ V : α from γ to δ as well. In other words, we need to coerce

Γ | γ ⊢ M : γ [reset] Γ | δ ⊢ reset M : γ Γ | γ ⊢ M : (α δ -→ γ) γ -→ γ [shift] Γ | γ ⊢ shift M : α
Γ | γ ⊢ V : α to Γ | δ ⊢ V : α.
This is exactly where the condition that the term V that we are substituting must be a value comes into play. If we look at the typing rules for values (variables and λ-abstractions), we see that the answer type is completely free and therefore if we can prove well-typedness w.r.t. one answer type, we also get it for all answer types. Proof. We will prove this property case by case for each reduction rule of λ shift . In the proof, we assume that the context C wrapping the redex and the contractum is just the empty context []. By the compositionality of the type system, it follows that if M → N preserves types, then so does

C[M ] → C[N ]. 1. M → β N
We know that M = (λx. M ′ ) V , that N = M ′ [x := V ] and that the derivation of the type of M looks like the following:

Γ, x : α | γ ⊢ M ′ : τ [abs] Γ | γ ⊢ λx. M ′ : α γ -→ τ Γ | γ ⊢ V : α [app] Γ | γ ⊢ (λx. M ′ ) V : τ
By applying Lemma 4.6.3 to the typing derivations of M ′ and V , we directly get the typing judgment we need.

M → reset N

We have M = reset V , N = V and the following derivation:

Γ | τ ⊢ V : τ [reset] Γ | γ ⊢ reset V : τ
If we recover the typing derivation for V , we run into the same issue as in the proof of Lemma 4.6.3. The context has changed from answer type γ to answer type τ . Again, we rely on the fact that the argument to reset must have been a value in order to be able to take the judgment

Γ | τ ⊢ M : τ and coerce it to a judgment Γ | γ ⊢ M : τ . 3. M → shift N We have M = reset (F [shift V ]), N = reset (V (λx. reset (F [x]))). Γ | τ ⊢ V : (α δ -→ τ ) τ -→ τ [shift] Γ | τ ⊢ shift V : α . . . F [] . . . Γ | τ ⊢ F [shift V ] : τ [reset] Γ | γ ⊢ reset (F [shift V ]) : τ
The validity of the above analysis hinges on the fact that the context separating the reset and the shift is an evaluation frame. If we look at the typing rules [app] and [shift], we see that the answer types of the subterms are always the same as the answer type of the compound term. This is what lets us assume that the answer type of both F [shift V ] and shift V is τ .

From this typing derivation, we will extract the typing judgment of V and the evaluation frame F that can take a term

M ′ such that Γ | τ ⊢ M ′ : α to a term F [M ′ ] such that Γ | τ ⊢ F [M ′ ] : τ . Γ | τ ⊢ V : (α δ -→ τ ) τ -→ τ Γ, x : α | τ ⊢ x : α . . . F [] . . . Γ, x : α | τ ⊢ F [x] : τ [reset] Γ, x : α | δ ⊢ reset (F [x]) : τ [abs] Γ | τ ⊢ λx. reset (F [x]) : α δ -→ τ [app] Γ | τ ⊢ V (λx. reset (F [x])) : τ [reset] Γ | γ ⊢ reset (V (λx. reset (F [x]))) : τ
The proof tree construction is straightforward, plugging in the two parts, V and F [], we got from the typing of M . The only peculiar point is our use of F [] in the environment Γ, x : α, which presupposes that x is fresh for F []. [START_REF] Knaster | Un théoreme sur les fonctions d'ensembles[END_REF] Property 4.6.5. Progress for λ shift Whenever we have a closed well-typed term M , i.e. one such that ∅ | γ ⊢ M : τ , then one of the following must hold:

• M = V for some value V • M = F [shift V ]
for some frame F and value V

• there exists an N such that M → N Proof. We will prove this property by showing that if M is not a value, then it must either contain a redex inside an evaluation context (and therefore be reducible) or be of the form F [shift V ]. We will proceed by structural induction and case analysis on the well-typed form of M . We will not consider the case of M being a variable or a λ-abstraction since they are both values (on top of that, a variable is an open term and therefore not typable in the empty environment ∅).

1. M = M 1 M 2
The typing derivation for M must look like this:

∅ | γ ⊢ M 1 : α γ -→ τ ∅ | γ ⊢ M 2 : α [app] ∅ | γ ⊢ M 1 M 2 : τ
We first call upon the induction hypothesis for M 1 and consider all three possible outcomes:

• M 1 = F 1 [shift V ] -then we have M = (F 1 [shift V ] M 2 ) = F [shift V ] where F = (F 1 M 2 ) • M 1 → N 1 -then we have M 1 M 2 → N 1 M 2 since ([] M 2 ) is a valid evaluation context • M 1 = V 1 -then we call upon the induction hypothesis for M 2 -M 2 = F 2 [shift V ] -then we have M = (V 1 (F 2 [shift V ])) = F [shift V ] where F = (V 1 F 2 ) -M 2 → N 2 -then we have V 1 M 2 → V 1 N 2 since (V 1 []) is a valid evaluation context -M 2 = V 2 -Since ∅ | γ ⊢ M 1 : α γ -→ γ and M 1 is a value, then M 1 = λx. M 11 (M 1 cannot be a variable because it must be a closed term). We therefore have M = (λx. M 11 ) V 2 which we can reduce to N = M 11 [x := V 2 ] using → β . 2. M = reset M ′
From the type of M , we can get a type for M ′ :

∅ | τ ⊢ M ′ : τ [reset] ∅ | γ ⊢ reset M ′ : τ M ′ is
another closed well-typed term and so we apply the induction hypothesis to M ′ and deal with the possible results:

• M ′ = V -we can reduce M = reset V to N = V using → reset • M ′ = F [shift V ] -we can reduce M = reset (F [shift V ]) to N = reset (V (λx. reset (F [x]))) using → shift • M ′ → N ′ -then we also have reset M ′ → reset N ′ since (reset []) is a valid evaluation context 3. M = shift M ′
We follow the same process. Analyze the type of M …

∅ | γ ⊢ M ′ : (τ δ -→ γ) γ -→ γ [shift] ∅ | γ ⊢ shift M ′ : τ
…apply the induction hypothesis and treat all the cases. Let M be a closed well-typed λ shift term whose expression type and answer type agree, i.e. we have ∅|τ ⊢ M : τ . Then the term reset M , which is also well-typed, can never reduce to a stuck term.

• M ′ = V -then we have M = F [shift V ] where F = [] • M ′ = F ′ [shift V ] -we have M = shift (F ′ [shift V ]) = F [shift V ] where F = (shift F ′ ) • M ′ → N ′ -we have shift M ′ → shift N ′ since (shift [])
Proof. Thanks to subject reduction, we know that all the terms N that we can ever reduce reset M to are all well-typed (and closed). Thanks to the progress property, we also know that any such N must satisfy one of the following properties:

• N is a value -therefore, N is not stuck

• N = F [shift V ] -This case is impossible. It would mean that N is not of the shape reset N ′ .
Somewhere in the reduction chain from reset M to N , the reset would have to be removed. The only reduction rule that can do that is → reset , repeated here:

C[reset V ] → reset C[V ]
It only applies when the argument of reset is a value. Furthermore, when applied in the empty context [], its result is also a value. Since values are irreducible (they are either simple variables or λ-abstractions, which are not valid evaluation contexts), then this → reset would have been the last reduction in the chain reset

M ↠ M ′ = reset V → reset V = N . However, this is in contradiction with N = F [shift V ].
• N → N ′ -N is not stuck because we can reduce to N ′ .

Having proven the type soundness of the above type system for λ shift , we now show that typed λ shift translates to typed λ . We have already defined a translation from λ shift terms to λ in 4.5, now we have to define a translation of the types. Definition 4.6.8. We define the interpretation τ of a λ shift type τ by:

• ν = ν where ν is an atomic type • α γ -→ β = α → F E γ ( β ) where E ω = {shift0 : ((δ → F E (ω)) → F E (ω)) ↣ δ} δ 78 ⊎ E
where E can be any effect signature as long as shift0 / ∈ E. [START_REF] Kuschert | A type-theoretic semantics for lambda-drt[END_REF] Property 4.6.9. Simulating λ shift types in λ

Γ | γ ⊢ M : τ ⇒ Γ ⊢ M : F E γ ( τ )
where Γ is defined by interpreting all of the pairs x : τ as x : τ .

Proof. We will proceed by induction on the proof of the judgment Γ | γ ⊢ M : τ , covering the 5 cases corresponding to the 5 different inference rules in the λ shift type system.

1. M = x x : τ ∈ Γ [var] Γ | γ ⊢ x : τ
We have x : τ ∈ Γ, which means that in Γ , we have x : τ . The interpretation of M , M , is η x and we can build a proof of the type judgment like this:

x : τ ∈ Γ [var] Γ ⊢ x : τ [η] Γ ⊢ η x : F E γ ( τ ) 2. M = λx. M ′ and τ = τ 1 δ -→ τ 2 Γ , m : ( τ → FE δ ( γ )) → FE γ ( γ ) ⊢ shift0! (λk. shift0: (λck. c k) (m ( • k))) : FE γ ( τ ) [abs] Γ ⊢ λm. shift0! (λk. shift0: (λck. c k) (m ( • k))) : (( τ → FE δ ( γ )) → FE γ ( γ )) → FE γ ( τ ) [≫=] Γ ⊢ M ′ ≫= (λm. shift0! (λk. shift0: (λck. c k) (m ( • k)))) : FE γ ( τ ) (b) The case for M = shift M ′ .

Other Control Operators

Other Control Operators

As we have seen in this chapter, there is more than one set of control operators with which we can endow a λ-calculus. One of the earliest variants is Felleisen's control/prompt [43]. Its semantics is similar to the one of shift/reset.

C[prompt V ] → prompt C[V ] C[prompt (F [control V ])] → control C[prompt (V (λx. F [x]))]
We have also explored shift0/reset0 and shift/reset. The former was interesting because of how closely its semantics matched the ones of λ . [START_REF] Lebedeva | Expression de la dynamique du discours à l'aide de continuations[END_REF] We also focused on the latter since it allowed us to show how a type system for continuations translates to the type system of λ . We did not study control/prompt, or their variants control0/prompt0. These operators have already been shown to be mutually expressible with shift/reset and shift0/reset0 [118].

When discussing control operators similar to effect handlers, we should mention the fcontrol/% operators of Sitaram [121].

C[(% V M )] → % C[V ] C[(% (F [fcontrol V ]) M )] → fcontrol C[M V (λx. F [x])]
This is very close to effect handlers. The delimiting operator % is packaged with a function M . This is like having a handler whose clause for treating fcontrol operations is M . Then, whenever fcontrol is invoked in its scope, M is applied to the parameter of fcontrol and to its continuation. The rule is identical to our op rule, [START_REF] Stephen C Levinson | Deixis. In The handbook of pragmatics[END_REF] the only difference being the fcontrol rule does not reinstate the handler in the body of the continuation. This means that the handler will only treat the first occurrence of the fcontrol effect: a notion known as shallow handlers [63].

For a comprehensive overview of control operators and their operational semantics, we recommend [1]. [START_REF] Lebedeva | Expression de la dynamique du discours à l'aide de continuations[END_REF] shift0/reset0 are also the control operators that one reaches for when implementing effect handlers using delimited continuations [63]. This means that not only can we use effect handlers to implement delimited continuations, we can also do the converse. [START_REF] Stephen C Levinson | Deixis. In The handbook of pragmatics[END_REF] Modulo presentation of contexts and evaluation order.

Part II

Effects and Handlers in Natural Language

Having developed the λ calculus in Part I, we will now turn our attention to its applications in natural language semantics. We interpret sentences involving deixis, conventional implicature, quantification, anaphora and presupposition as λ computations in which these phenomena are expressed as side effects/operations. This will allow us to construct a grammar in which all of these phenomena are present. Within this grammar, sentences are interpreted as computations that have access to all of the linguistic side effects at the same time.

Introduction to Formal Semantics

Semantics is the study of the meaning of language. In this chapter, we will review the very basics of a school of formal semantics which originated with Richard Montague in the early 70's [96, 97, 98] (5.1). We will then present a formalism that embodies the principles of montagovian semantics, the Abstract Categorial Grammars [35] (5.2). In Chapter 7, we will be analyzing anaphora in λ by emulating theories of dynamic semantics. To that end, we briefly present dynamic semantics by introducing two of its incarnations: Discourse Representation Theory [64] (5.3) and Type-Theoretic Dynamic Logic [38, 80] (5.4).

106

Chapter 5. Introduction to Formal Semantics

In the 20th century, mathematical logic studied similar properties on formal artificial languages, leading to the developments of new ideas such as model theory and Tarski's definition of truth [58, 127]. Montague then argues that natural languages deserve the same formal treatment as the artificial languages of logic and mathematics:

There is in my opinion no important theoretical difference between natural languages and the artificial languages of logicians; indeed, I consider it possible to comprehend the syntax and semantics of both kinds of language within a single natural and mathematically precise theory.

Universal Grammar [97] In formal logic, the formulas of the artificial languages are defined inductively, by a series of construction rules. The definition of truth is then inductive on the structure of the formula: for every rule that lets us form a logical formula, there is a rule which tells us how to compute its truth value in a model. In his approach, Montague applies the very same strategy to natural language [98].

Syntax

Contrary to propositional logic, whose language is made only of propositions, the set of which is given inductively, natural language expressions fall into many syntactic categories. Montague therefore defines the expressions of a language as a family of sets, indexed by categories. The categories are defined inductively as well: e is a category (of entity-denoting expressions), t is a category (of truth-denoting expressions) and for every two categories A and B, A/B and A/ /B are categories. [START_REF] Blain | Call-by-push-value: A subsuming paradigm[END_REF] Montague identifies some of the categories which will become useful in formulating the grammar. In our example, we will make use of the following four:

• IV = t/e, the category of intransitive verbs • T = t/IV , the category of terms (i.e. noun phrases)

• T V = IV /T , the category of transitive verbs

• CN = t/ /e, the category of common nouns Having established the categories, we will now give some of the construction rules in Montague's grammar. The sets P A of phrases of category A are defined as the smallest sets being closed on the following construction rules (taken almost verbatim from [98]):

S1 B A ⊆ P A for every category A.
Here, B A is the set of basic expression of category A. For the categories that we are interested in, these sets look something like this: B T V = {eat, love, find, . . .} B CN = {man, woman, unicorn, . . .} [START_REF] Blain | Call-by-push-value: A subsuming paradigm[END_REF] The meanings of these connectives will be given by their use in the grammar, but intuitively, A/B is the category of expressions that when combined with an expression of category B yield an expression of category A, and A/ /B is the category of expressions that denote functions from the meanings of category B to the meanings of category A. [START_REF] Lewis | General semantics[END_REF] B T contains a countably infinite set of T -typed variables he 0 , he 1 , he 2 , …

B IV = {run,

Montague Semantics

107

S2 If ζ ∈ P CN , then F 0 (ζ), F 1 (ζ), F 2 (ζ) ∈ P T ,
where Note that Montague maintains a distinction between deep syntax (tectogrammar) and surface syntax (phenogrammar). For example, the rule S4 tells us that a noun phrase α ∈ P t/IV can be combined with an intransitive verb δ ∈ P IV to yield a sentence F 4 (α, δ) (this is tectogrammar). Then, the definition of F 4 tells us that the noun phrase should precede the verb phrase and that the verb phrase should be in third-person singular present [START_REF] Lindley | Do be do be do[END_REF] (this is phenogrammar). Similarly for the rule S5, it tells us that a transitive verb δ ∈ P IV /T can be combined with a noun phrase β ∈ P T to form an (intransitive) verb phrase F 5 (δ, β). The definition of F 5 then tells us that such a verb phrase is pronounced/written with the transitive verb first and the noun phrase second and that the noun phrase should be in accusative form. In S2, this is the case as well. The rule tells us that for every noun ζ ∈ P CN , there are the universal, definite and indefinite noun phrases F 0 (ζ), F 1 (ζ) and F 2 (ζ) respectively. The definitions of F 0 , F 1 and F 2 then give us the surface realizations of these noun phrases. [START_REF] Mac | Categories for the working mathematician[END_REF] Using the grammar given above, we can derive, e.g., the sentence every man loves a unicorn. We can record the rules we have used when constructing the sentence in a derivation tree (also called an analysis tree in [98]

F 0 (ζ) = every ζ F 1 (ζ) = the ζ F 2 (ζ)

. . man

This is not the only way we can derive this sentence. This is another valid analysis which yields the same string of symbols: [START_REF] Liang | Monad transformers and modular interpreters[END_REF] The names of the rules Si and of the functions F j were kept the same as in [98] for easier reference. Since we are not reproducing the whole grammar, you might notice that some numbers are left out. [START_REF] Lillibridge | Exceptions are strictly more powerful than call/cc[END_REF] i.e. α ∈ P T 86 i.e. δ ∈ P T V [START_REF] Lindley | Do be do be do[END_REF] All the noun phrases in this fragment are third-person singular. [START_REF] Mac | Categories for the working mathematician[END_REF] If we were to write a grammar of French, we would keep the same tectogrammar and just replace the definitions of F 0 , F 1 and F 2 to use chaque, le/la/l' and un/une.

. . unicorn

These two derivations will explain the ambiguity of the sentence. As we will see next, the first derivation will produce the subject-wide scope reading: every man loves some unicorn, not necessarily the same one. The second derivation, in which the noun phrase a unicorn scopes over the rest of the sentence, will give us the object-wide scope reading: there is a unicorn and every man loves it.

There are infinitely many more derivations of this sentence in this grammar, [START_REF] Maršík | Algebraic effects and handlers in natural language interpretation[END_REF] but their meanings are all equivalent to one of the two analyses we have seen above.

Semantics

Now that we have defined the expressions of our fragment of English, we will study their meaning by establishing their truth conditions: under which conditions (i.e. in which world or model) the sentence is true.

Methodologically, Montague first proposes introducing a formal logic (an artificial language) that is suitable to describe the truth conditions of the natural language under study. Instead of computing directly the truth value of a sentence in a model, Montague translates sentences of natural language into this formal logic. In [98], this formal logic is a higher-order tensed intensional logic with the standard logical connectives, quantifiers over objects of any type, the modal operator of necessity □ and the past and future modalities H and W . The modalities and the tenses were introduced by Montague to model specific problems in the semantics of a natural language (intensional verbs and tensed verbs). These phenomena will not feature in the small extract from his fragment that we will demonstrate here and therefore we will simplify Montague's approach to use plain higher-order logic (i.e. the λ-calculus).

We establish the meaning of a sentence by translating it to a corresponding formula in higher-order logic (a term of type t) whose meaning will become the meaning of the sentence. However, the expressions of our language are composed not only of sentences (P t ), but also of noun phrases (P T ), common nouns (P CN ), transitive verbs (P T V ) . . . We will interpret these as terms of higher-order logic of different types. The scheme that connects the syntactic categories to the types of interpretations is given below:

f (t) = t f (e) = e f (A/B) = f (A/ /B) = f (B) → f (A)
Unsurprisingly, the categories t and e of truth-denoting and entity-denoting expressions will be translated to truth values and entities, respectively. The category A/B is the category of expressions that can combine with expressions of category B to form a complex expression of category A. Frege's principle of compositionality states that the meaning of a complex expression ought to be a function of the meanings of its parts. Accordingly, Montague interprets an expression of category A/B as a function from the meanings of the parts (category B) to the meanings of the complex expressions (category A). Finally, the category A/ /B is intended to be the category whose meanings are functions from B to A.

We can apply this definition to the set of categories that feature in our fragment to see what type of interpretation corresponds to each category:

f (t) = t f (T ) = f (t/IV ) = f (t/(t/e)) = (e → t) → t f (CN ) = f (t/ /e) = e → t f (IV ) = f (t/e) = e → t f (T V ) = f (IV /T ) = f ((t/e)/(t/(t/e))) = ((e → t) → t) → e → t
Sentences are expressions of category t and so are interpreted as truth values. Noun phrases (category T ) are interpreted as functions of type (e → t) → t. We call such functions generalized quantifiers. They include the quantifiers ∃ and ∀, as well as functions such as λP. ∀x. man(x) → P (x), which will serve as the meaning of the noun phrase every man. The gist of the idea behind generalized quantifiers is that we can represent the meanings of noun phrases such as some unicorn, every pony or Bill as the sets of properties that they satisfy (i.e. which properties hold for some unicorn, which hold for every pony, and which hold for Bill). [START_REF] Martin | A dynamic categorial grammar[END_REF] Next up, common nouns (category CN ) are interpreted as sets of entities (e.g. the meaning of unicorn is the set of all entities that are unicorns). Likewise, intransitive verbs (category IV ) become predicates on entities. Finally, we have transitive verbs (category T V ). Syntactically, they combine with an object, which is a noun phrase (category T ), to produce a verb phrase (category IV ). They will therefore be interpreted as functions from generalized quantifiers (the interpretations of noun phrases) to predicates on entities (the interpretations of verb phrases), type ((e → t) → t) → e → t. We can view this type as the type of relations between generalized quantifiers (the objects) and entities (the subjects).

Now that we have decided on the nature of the interpretations that we want to assign to expressions in our fragment, it is time to define the interpretation. For every syntactic construction rule, there will be a corresponding semantic translation rule. If we view the syntactic construction rules as an inductive definition of the expressions in our language, the semantic translation rules are the individual cases of a definition by induction on the structure of these expressions.

T1

We interpret the basic expressions the following way:

• John, Mary and Bill translate to λP. P (j), λP. P (m) and λP. P (b), respectively, where j, m and b are constants of type e 91

• he n translates to λP. P x n , where x n is a free variable of type e

• a transitive verb δ ∈ B T V translates to the function λOs. O (λo. δ ′ (s, o)), where δ ′ is a binary relation on entities (type e → e → t) [START_REF] Mccarthy | A basis for a mathematical theory of computation[END_REF] • other basic expressions translate to constants of the corresponding type (e.g. the common noun man ∈ B CN translates to a predicate man ′ : e → t) [START_REF] Martin | A dynamic categorial grammar[END_REF] The type A → t can both be seen as a property of As and a set of As (given by its characteristic function). The type (e → t) → t can thus be seen as a set of properties of entities. [START_REF] Mcbride | Applicative programming with effects[END_REF] We have to do this because even though we can model proper nouns as constants designating entities, in our fragment, noun phrases are analyzed as generalized quantifiers (in order to account for noun phrases such as every man). Therefore, we have to lift the entities j, m and b to generalized quantifiers. The definition λP. P (j) states that a property P holds for John if and only if it holds for the entity j. This construction is known as type raising and it is an instance of the generalizing-to-the-worst-case scenario (i.e. even though proper nouns are not quantificational, they have to be raised into generalized quantifiers since other noun phrases might be quantificational). [START_REF] Mccarthy | A basis for a mathematical theory of computation[END_REF] In [98], Montague interprets transitive verbs as constants of type ((e → t) → t) → e → t, but then he adds a condition that effectively restricts them to be of the form λOs. O (λo. δ ′ (s, o)). We also reorder the arguments to the binary relation so that the subject s goes before the object o. This way, the meaning of the sentence John loves Mary becomes love ′ (j, m) and not love ′ (m, j). where G 4 (α ′ , δ ′ ) = α ′ (δ ′ ).

T2 If ζ ∈ P CN and ζ translates to ζ ′ , then F 0 (ζ) translates to G 0 (ζ ′ ), F 1 (ζ) translates to G 1 (ζ ′ ) and F 2 (ζ) translates to G 2 (ζ ′ ), where G 0 (ζ ′ ) = λP. ∀x. ζ ′ (x) → P (x) G 1 (ζ ′ ) = λP. ∃x. (∀y. ζ ′ (y) ↔ x = y) ∧ P (y) G 2 (ζ ′ ) = λP. ∃x. ζ ′ (x) ∧ P (x)
T5 If δ ∈ P T V /T , β ∈ P T , and δ, β translate to δ ′ , β ′ respectively, then

F 5 (δ, β) translates to G 5 (δ ′ , β ′ ), where G 5 (δ ′ , β ′ ) = δ ′ (β ′ ).
T14 If α ∈ P T , ϕ ∈ P t , and α, ϕ translate to α ′ , ϕ ′ respectively, then F 10,n (α, ϕ) translates to G 10,n (α ′ , ϕ ′ ), where G 10,n (α

′ , ϕ ′ ) = α ′ (λx n . ϕ ′ ).
This completes the definition of the semantics for our fragment. We can now use it to find the meanings of expressions described by our grammar. In the previous subsection, we have seen two derivations of the surface form of the sentence every man loves a unicorn. We can now use the semantics to show the translations into higher-order logic side-by-side with the surface form realizations. First, we get the subject-wide scope reading of the sentence: Even though both derivations lead to the same surface forms, the meanings predicted by the two derivations differ, which is how we account for the ambiguity of natural language in a formal setting.

Abstract Categorial Grammars

111 Γ ⊎ {x : α} ⊢ Σ M : β [abs] Γ ⊢ Σ λx. M : α -• β Γ ⊢ Σ M : α -• β ∆ ⊢ Σ N : α [app] Γ ⊎ ∆ ⊢ Σ M N : β x : α ⊢ Σ x : α [var] ⊢ Σ c : τ (c) [const]
Figure 5.1: The typing rules for the linear λ-calculus.

Summary

In this section, we have seen the essence of montagovian semantics. We define (usually a small fragment of) natural language using a formal system. For every syntactic construction, there is a description of how to compute the meaning of the construction from the meanings of its constituents. The meanings of sentences are truth values in a mathematical model which represents the state of affairs in the real world. There are other features of Montague grammar that are not essential, but frequently reappear in current formulations of Montague's approach:

• The meaning of a sentence is described in a formal logic. The interpretation of a sentence is then realized by translating sentences of the natural language to formulas of the logic.

• Sentences are built out of constituents which do not all denote truth values (e.g. verb phrases denote predicates). The λ-calculus is used to glue the meanings of all the constituents together. This usually means that the logic in which we interpret natural language is higher-order logic.

• The calculus which governs the possible syntactic derivations is based on categorial grammar. Lexical items can be seen as functions, e.g. a transitive verb is a function from noun phrases (objects) to verb phrases, and their meanings become functions as well.

Montague's work was very influential in the field of natural language semantics. The ideas of Montague stood at the origin of several grammatical frameworks that focus on the syntax-semantics interface [35, 100, 107, 90]. In the next section, we will review one of them.

Abstract Categorial Grammars

Philippe de Groote's abstract categorial grammars (ACGs) are a grammatical formalism which makes it easy to define Montague-like semantics for fragments of natural languages [35]. It is this formalism that we will be using in the second part of this manuscript and so we will dedicate this section to a brief introduction. We start by presenting the formal definition and then we look at an example of analyzing the syntax and the semantics of a fragment similar to the one we have seen in the Montague example in 5.1.

Definition

The objects at the heart of ACGs are λ-terms. The syntax is the same as in Chapter 1, restricted to abstractions, applications, variables and constants. The important difference comes in the type system. The function type is written as α -• β and the typing rules differ (see Figure 5.1). This type system enforces the constraint that every λ-binder binds exactly one occurrence of a variable. [START_REF] Meijer | Functional programming with bananas, lenses, envelopes and barbed wire[END_REF] In the typing rules, we make use of the ⊎ operator from Section 1.3 which gives us the union of Γ and ∆, where the domains of Γ and ∆ must be disjoint.

As with λ , the linear λ-calculus is parameterized by a set of atomic types and set of typed constants. In ACG terminology, this information is grouped in a higher-order signature. With ACGs, we will represent the derivations (i.e. the tectogrammatical structures) of sentences as linear λ-terms. In Section 5.1, we have seen how in Montague semantics, the derivation of a phrase can be seen as a computation that produces its surface form (the rules in Subsection 5.1.1) or as a computation that produces its meaning (the rules in Subsection 5.1.2). We will now define the ACG notion of interpreting derivations.

Definition 5.2.2. A lexicon

from signature Σ 1 = ⟨A 1 , C 1 , τ 1 ⟩ to signature Σ 2 = ⟨A 2 , C 2 , τ 2 ⟩ is a pair ⟨F, G⟩ where: • F : A 1 → I(A 2 ) is a function that interprets the atomic types of Σ 1 as types in Σ 2 , • G : C 1 → Λ(Σ 2 ) is a function that interprets the constants of Σ 1 as linear λ-terms in Σ 2 ,
• and the interpretations are well-typed, meaning that for every c ∈ C 1 , we have ⊢ G(c) : F (τ (c)) [START_REF] Moggi | An abstract view of programming languages[END_REF] With these definitions in place, we can start tracing the parallels between Montague's grammar and ACGs. The level of deep syntactic structure is represented by a higher-order signature Σ 1 . Its constants are the basic expressions and the syntactic construction rules from Subsection 5.1.1 and its types are the categories. The types of the construction rules reflect the types of the constituents and of the resulting complex expression. For example, the construction rule F 0 , which maps common nouns ζ to the noun phrases every ζ, has the type CN -• T . The target of our semantic translation, higher-order logic, is also represented by a higher-order signature, Σ 2 . Its constants are the logical connectives, quantifiers and the relations that we assume to have in the model (man ′ , unicorn ′ , love ′ …). Its types are e, the type of entities, and t, the type of truth values. The translation that we described in Subsection 5.1.2 would correspond to a lexicon from Σ 1 to Σ 2 . The interpretation of types would be the homomorphic function f and the interpretation of the constants would be the functions G i which mirror the syntactic constructors

F i .
We finish with the formal definition of an abstract categorial grammar.

Definition 5.2.3. An abstract categorial grammar is a quadruple ⟨Σ 1 , Σ 2 , L, s⟩, where:

• Σ 1 = ⟨A 1 , C 1 , τ 1 ⟩ is a higher-order signature that we will call the abstract signature (sometimes also called the abstract vocabulary)

• Σ 2 = ⟨A 2 , C 2 , τ 2 ⟩ is a higher-order signature that we will call the object signature (also called the object vocabulary)

• L : Σ 1 → Σ 2 is a lexicon from Σ 1 to Σ 2 • s ∈ I(A 1
) is a type from the abstract signature that we will call the distinguished type Definition 5.2.4. The abstract language A(G) of an ACG G = ⟨Σ 1 , Σ 2 , L, s⟩ is the set [START_REF] Moggi | Notions of computation and monads[END_REF] In our analogy to Montague, by taking the distinguished type to be the category t of truth-denoting expressions, the abstract language is the language of derivations of sentences. The object language is then the language of meanings expressible by the sentences of our language. If we would instead take the ACG where the object signature is the signature of strings and the lexicon is the lexicon mapping syntactic constructions to their surface realizations (i.e. the F i functions from Subsection 5.1.1), then we would get English strings as the object language. [START_REF] Moggi | An abstract view of programming languages[END_REF] Here we are applying F : A 1 → I(A 2 ) to a type τ (c) ∈ I(A 1 ). Whenever F : A 1 → I(A 2 ) is an interpretation of atomic types, we will also use F for its (unique) homomorphic extension, which maps types in I(A 1 ) to types in I(A 2 ) by replacing all the atomic types with their interpretations. We will also be doing the same when extending an interpretation G : C 1 → Λ(Σ 2 ) to terms in Λ(Σ 1 ). The homomorphic extension of G will replace all the constants in the term with their interpretations. [START_REF] Moggi | Notions of computation and monads[END_REF] When L = ⟨F, G⟩ is a lexicon, M is a λ-term and τ is a type, we will write L(M ) for G(M ) and L(τ ) for F (τ ).

{M | ⊢ Σ1 M : s}. Definition 5.2.5. The object language O(G) of an ACG G = ⟨Σ 1 , Σ 2 , L, s⟩ is the set {L(M ) | M ∈ A(G)}.

Syntax

We will now go through a simple example of ACGs, taken from [105], that parallels the extract from Montague that we have seen in Section 5.1. We start by defining a higher-order signature that will describe the derivations of the expressions of our fragment of English:

J, M, B : N P , ,  :

N P -• N P -• S , ,  : N -• (N P -• S) -• S , ,  : N
In this manuscript, we will establish higher-order signatures by giving type assignments such as those above. The constants can be read off from the domain of the assignments and the atomic types can be read off from the atomic types that occur in the assigned types. In this particular signature, the constants are J, M, B, , , , , , , ,  and . The atomic types are S (sentences, t in Montague's grammar), N P (noun phrases, e in Montague's grammar (Montague's T corresponds to (N P -• S) -• S)) and N (common nouns, CN = t/ /e in Montague's grammar). The determiners ,  and  have the type N -• (N P -• S) -• S. In this grammar, all quantificational noun phrases are raised. The type N P -• S can be seen as the type of sentences S with a free variable of type N P . The phrase   : (N P -• S) -• S takes such a sentence as an argument and binds the free N P variable within. [START_REF] Montague | English as a formal language. Linguaggi nella societae nella tecnica[END_REF] This signature describes the deep syntax (tectogrammar) of a fragment of English. For such signatures, we will follow the convention of using   when typesetting the constants. This signature will be the abstract signature of an ACG. We will now define another signature to serve as the object signature and give a lexicon that interprets one in terms of the other. The signature of strings is defined below: John, Mary, Bill, eat, love, find : string every, the, a, man, woman, unicorn : string

(_ + _) : string -• string -• string
This signature has a single atomic type, string. For every word that features in our grammar, there is a string-typed constant in the signature. There is also a binary concatenation operator on strings, which we will write in infix form. [START_REF] Montague | Universal grammar[END_REF] We can now give a lexicon _ syntax that will map deep syntax into strings of words, i.e. surface syntax. On the type level, sentences, noun phrases and common nouns will all be interpreted as strings:

S syntax = string N P syntax = string N syntax = string
We can now give an interpretation to all of the constants of the syntactic signature: [START_REF] Montague | English as a formal language. Linguaggi nella societae nella tecnica[END_REF] Much the same way that the rules F 10,n from S14 and G 10,n from T14 do in Montague's grammar. [START_REF] Montague | Universal grammar[END_REF] String concatenation is associative. However, there is nothing guaranteeing that this is the case for our (_ + _) operator. We could make it be the case by introducing another lexicon which would encode the string literals and string concatenation as Church strings and function composition. These two signatures, the lexicon and the distinguished type S together form an ACG. The abstract language of this ACG generates syntactic derivations, such as the terms t 1 and t 2 given below.

t 1 =   (λx.   (λy.  y x)) t 2 =   (λy.   (λx.  y x))
The object language contains strings which are the surface realizations of the derivations generated by the abstract language. Therefore, it contains the following English sentence, which can be produced by interpreting either t 1 or t 2 : t 1 syntax = every + man + loves + a + unicorn t 2 syntax = every + man + loves + a + unicorn As in the case of Montague's grammar (Subsection 5.1.1), we have two derivations for this sentence. One of the two, t 1 , will lead to the subject-wide scope reading of the sentence whereas the other, t 2 , will lead to the object-wide scope reading. As in Montague's grammar, ambiguity is explained by the fact that there exist multiple derivations which all yield the same surface realization. Furthermore, Montague noted that in his grammar, there is an infinity of derivations for this sentence, though their differences are unimportant (they are all essentially equivalent to one of the two analyses that we have here). In ACGs, this notion is made precise. The sentence above also has an infinity of possible derivations (e.g.   (λx.   ( x))). However, every such derivation is βη-equivalent to either t 1 or t 2 , whereas t 1 and t 2 are not βη-equivalent (they have different βη-normal forms).

Semantics

We will now give a semantics to our fragment. We will introduce a new object signature (that of higherorder logic) and define a lexicon that will interpret the lexical items of our deep syntax abstract signature in higher-order logic. First, we define the signature of logic:

5.2. Abstract Categorial Grammars 115 ⊤, ⊥ : o ¬ : o → o (_ ∧ _), (_ ∨ _), (_ → _), (_ ↔ _) : o → o → o ∃, ∀ : (ι → o) → o _ = _ : ι → ι → o j, m, b : ι man, woman, unicorn : ι → o eat, love, find : ι → ι → o
The atomic types are o, the type of propositions, and ι, the type of individuals. [START_REF] Montague | The proper treatment of quantification in ordinary english[END_REF] The signature includes constants for a tautology (⊤) and a contradiction (⊥), the unary logical operator of negation (¬), the binary connectives of conjunction (_ ∧ _), disjunction (_ ∨ _), implication (_ → _) and equivalence (_ ↔ _), the existential and universal quantifier over individuals (∃ and ∀), and an equality relation on individuals (_ = _). Furthermore, the signature contains constants from the model: the individuals j, m and b, the unary relations man, woman and unicorn, and the binary relation eat, love and find. We adopt the convention of using boldface fonts to typeset the constants of our model. We also use single-letter names for individual constants.

We note that the types make use of the usual function types α → β instead of the linear function type α -• β. In (higher-order) logic, it is often the case that a bound variable occurs more than once in its scope, as we will shortly see in the interpretations. This is a liberty that we will take when dealing with semantic lexicons. The calculus into which we will be translating will not always be the linear λ-calculus.

It will suffice for it to be any calculus which includes the simply-typed (linear) λ-calculus. The simplytyped λ-calculus, which we will make use of in this interpretation, is one such calculus. λ , which we will use in the upcoming chapters, is another.

We will now give the lexicon _ that interprets the syntactic constructions of our fragment in (higherorder) logic. First, we identify the type of interpretations for the atomic abstract types:

S = o N P = ι N = ι → o A -• B = A → B
This follows what we have seen in Montague's semantic interpretation (definition of f in Subsection 5.1.2). The type S (t in Montague) is interpreted as o (t in Montague), the type N P (e in Montague) is interpreted as ι (e in Montague) and the type N (CN = t/ /e in Montague) is interpreted as ι → o (e → t in Montague). In ACGs, it is always the case that A -• B = A -• B . [START_REF] Muskens | Combining montague semantics and discourse representation[END_REF] However, since our target calculus is no longer the linear λ-calculus, the linear function connective (_ -• _) is replaced by the usual connective (_ → _). This is very similar to Montague's grammar, where the connective (_/_) on syntactic categories is translated to the function space connective (_ → _).

With the interpretations of types in place, we can give the interpretations of all the syntactic constructors: In our manuscript, we will use the term lexical entry to refer to the individual interpretations of the constructors in our grammar.

Using the _ lexicon, we can interpret the terms t 1 and t 2 from the previous subsection to get the two reading of the sentence "every man loves a unicorn". t 1 = ∀x. man x → (∃y. unicorn y ∧ love x y) t 2 = ∃y. unicorn y ∧ (∀x. man x → love x y)

Summary

We have seen how ACGs can be used to implement Montague's program of defining fragments of natural languages and giving them a compositional model-theoretic semantics. ACGs make explicit the notion of derivation trees, which are generated by a simple type system. These derivation trees (abstract terms) are then interpreted piece-by-piece (a homomorphism that interprets constants), which guarantees compositionality of the interpretation.

In our manuscript, we will be using ACGs as our grammatical formalism. We will be ignoring the lexicons that defines the surface realization of sentences: their definitions would be either trivial or fraught with detail (such as morphological agreement) that we are not interested in our thesis. Throughout the manuscript, we will therefore make use of ACGs in two modes: we will be introducing lexical items into the abstract signature of deep syntax with declarations of the form  : T Y P E and we will be giving their interpretations as lexical entries of the form  = lambda-banana-term. The calculus in which we will be giving the meanings of lexical items will be λ .

You might have noticed that we have already used this style in the first part of the manuscript. In Chapter 2, when we were building up our simple calculator language and giving its semantics, we were using ACGs. [START_REF] Muskens | Lambda grammars and the syntax-semantics interface[END_REF]

Discourse Representation Theory

Montague's approach of evaluating natural language in a model has been extended to linguistic units larger than a single sentence. The crucial observation when dealing with linguistic discourse is that the meanings (i.e. truth values) of the sentences that make it up cannot be computed independently, without considering the context in which they appear. If we look at the sentence in Example 4, we cannot describe its truth conditions as we do not know to what the pronouns it and him refer. fascinate ? ?

However, if we place this sentence in a context which provides suitable antecedents for the pronouns, as in Example 5 from [64], we can find the proposition that represents the sentence's truth conditions.

(5) Jones 1 owns Ulysses 2 . It 2 fascinates him 1 .

own j u ∧ fascinate u j Furthermore, the contribution of a sentence can be more complicated than conjoining a new proposition to the logical representation of the preceding discourse. Let us consider an example from [64] (Example (1.28), Section 1.1.3):

(6) Jones 1 owns a Porsche 2 . It 2 fascinates him 1 .

(∃x. Porsche x ∧ own j x) ∧ fascinate x ? j (∃x. Porsche x ∧ own j x ∧ fascinate x j)

In Example 6, the first sentence contains an indefinite and the truth conditions of the sentence are thus expressed by an existentially quantified formula. In the second sentence, the pronoun refers to the indefinite from the first sentence. We would therefore like the referent of the pronoun to co-vary with the referent of the indefinite. However, the variable x which designates the referent of the indefinite is not in scope of the second sentence. Instead of just conjoining the two propositions, we would like to insert the proposition under the scope of the existential quantifier contributed by the indefinite of the first sentence. [START_REF] Nouwen | Dynamic semantics[END_REF] These issues with anaphora are not limited to examples that span multiple sentences. We can see the same phenomenon in the single-sentence Example 7 and its paraphrase in Example 8. If we try to compute the meaning of the noun farmer who owns a donkey in Montague semantics, [START_REF] Nunberg | The linguistics of punctuation[END_REF] we get the predicate λx. farmer x ∧ (∃y. donkey y ∧ own x y). However, using this interpretation for the relative clause, we get the first logical form under Example 7, in which the pronoun is not in scope of the variable y that refers to the donkey. Again, we can get the correct reading by lifting and extending the scope of the quantifier contributed by the indefinite.

A similar thing happens in Example 8, which paraphrases Example 7. The (montagovian) meaning of the antecedent a farmer owns a donkey is the proposition ∃xy. farmer x ∧ donkey y ∧ own x y. However, if we use this meaning in the conditional of Example 8, the consequent he beats it will be outside the scope of the variables x and y that refer to the farmer and the donkey respectively. This leads to the first logical form under Example 8, which is unsatisfactory since the x and y variables are not correctly bound. Yet again, the desired logical representation can be recovered by lifting and extending the scope of the quantifiers contributed by the indefinites.

When Montague wanted to treat intensional and tensed verbs in his fragment, he decided to translate natural language to a formal logic which was intensional and tensed. A similar strategy was employed by semanticists who studied dynamic phenomena (such as anaphora) and developed their dynamic logics [53, 64, 38, 80]. In dynamic logic, (∃x. A) ∧ B becomes equivalent to (∃x. A ∧ B) and (∃x. A) → B becomes equivalent to (∀x. A → B). With these equivalences, we can lift and extend the scope of indefinites so as to obtain the binding that we observe in natural language.

Our analysis of dynamics using λ draws on two theories of dynamic semantics: Discourse Representation Theory (DRT) [64] and Type-Theoretic Dynamic Logic (TTDL) [38, 80]. In this section, we briefly introduce DRT and in the next, we talk about TTDL.

Discourse Representation Structures

In DRT, sentences contribute to the construction of a Discourse Representation Structure (DRS). This structures serve at the same time as the representation of the content of the discourse and also as the context in which any subsequent discourse is evaluated.

We begin the formal definition by assuming an infinite set D of discourse referents. These are just like the variables of first-order logic; they are symbolic references to individuals. Our formalization will also rely on a vocabulary of relation symbols. . . , c m }⟩ will be usually presented using the following notation:

x 1 … x n c 1 . . . c m
We will formalize the meaning of DRSs in the next two subsections. For now, we can think of the DRS ⟨{x 1 , . . . , x n }, {c 1 , . . . , c m }⟩ as standing for the formula ∃x 1 . . . x n . c 1 ∧ . . . ∧ c m .

DRSs are computed incrementally, starting from the empty DRS:

If we were to interpret the discourse in Example 6, we would start with the first sentence. Both indefinites and proper nouns are handled by introducing a new discourse referent and a condition that describes them. After interpreting the subject Jones and the object a Porsche, we would get the following DRS:

x y Jones x103 Porsche y

The transitive verb owns will then add another condition to the DRS. Its arguments will be the discourse referents that correspond to the subject and the object.

x y Jones x Porsche y own x y

This DRS is the result of interpreting the first sentence of Example 6. We can now use it as the context for interpreting the second sentence. Pronouns choose a discourse referent accessible from the DRS in which they are to be interpreted. [START_REF] Gordon D Plotkin | Handling algebraic effects[END_REF] The neutral pronoun it will choose y, since from the presence of the Porsche y condition, we can infer it designates an inanimate object. The masculine pronoun him will select x because it designates a masculine entity. Then as in the case of the previous sentence, the transitive verb contributes a condition that will relate the referent of the subject to the referent of the object.

x y Jones x Porsche y own x y fascinate y x

The precise mechanism of DRS construction will be given in Section 7.1, where we will see the derivation of the DRS for Example 6 in more detail. In the rest of this section, we will talk about the truthconditional meaning of DRSs and of the accessibility relation.

DRSs as Contents

The result of interpreting a discourse in DRT is a DRS. Our interest in interpreting natural language is to be able to recover the truth conditions of a linguistic utterance. Therefore, we need a way to read off the truth conditions of a discourse from a DRS. We find that the most instructive way to give a formal semantics to DRT is to give a translation to an already established logic. In the case of our formalization of DRT, we will be translating DRSs and DRS conditions to first-order logic. [START_REF] Pogodalla | Generalizing a proof-theoretic account of scope ambiguity[END_REF] Definition 5.3.3. We define a mapping (_) fo from DRSs and DRS conditions to first-order logic formulas by the following rules:

• x 1 … x n c 1 . . . c m fo = ∃x 1 . . . x n . c fo 1 ∧ . . . ∧ c fo m •       x 1 … x n c 1 . . . c m ⇒ K       fo = ∀x 1 . . . x n . (c fo 1 ∧ . . . ∧ c fo m ) → K fo • (P x 1 . . . x n ) fo = P x 1 . . . x n • (¬K) fo = ¬(K fo ) • (K 1 ∨ K 2 ) fo = K fo 1 ∨ K fo 2
In the translation defined above, the first two rules expose the nature of DRSs. As more and more conditions are added to a DRS, they all fall under the scope of the existential quantifiers introduced by the universe of the DRS. This intuitively corresponds to the (∃x. A) ∧ B = (∃x. A ∧ B) law of dynamic logic. Furthermore, any (existentially quantified) variables contributed by a DRS which acts as an antecedent in an implication take scope over the consequent of the implication using universal quantification. This is a realization of the (∃x. A) → B = (∀x. A → B) law of dynamic logic.

We can now retrieve the truth conditions of the DRS that we have computed in the previous subsection.

x y Jones x Porsche y own x y fascinate y x fo = ∃xy. Jones x ∧ Porsche y ∧ own x y ∧ fascinate y x Assuming that j is the only individual that satisfies the Jones predicate, this proposition is equivalent to the reading that we have given before.

As another example, we can take the DRS that is the result of interpreting the sentence in Example 7.

x y farmer x donkey y own x y ⇒ beat x y fo = ∀xy. (farmer x ∧ donkey y ∧ own x y) → beat x y Note that in the above DRS, the discourse referents x and y in the consequent of the implication are bound by the universe of the DRS that is the antecedent of the implication. We will explain the notions of scope and accessibility in DRT in the next subsection.

DRSs as Contexts

After having interpreted a part of discourse as a DRS, that DRS then serves as the context in which further discourse is to be evaluated. An important feature of the context is the set of discourse referents it makes available for anaphoric binding in subsequent discourse. The availability of these referents is governed by the notion of accessibility, which we define formally along with the notion of DRS subordination. Definition 5.3.4. An occurrence of a DRS K i = ⟨U i , C i ⟩ within a DRS K is immediately subordinate to an occurrence of a DRS K j = ⟨U j , C j ⟩ within the same DRS if one of the following is true:

• ¬K i ∈ C j • K i ⇒ K ′ ∈ C j for some DRS K ′ • K i ∨ K ′ ∈ C j for some DRS K ′ • K ′ ∨ K i ∈ C j for some DRS K ′ • K j ⇒ K i occurs within K Definition 5.3.5.
The relation "K i is (weakly) subordinate to K j " is defined as the (reflexive)-transitive closure of the relation "K i is immediately subordinate to K j ". Definition 5.3.6. An occurrence of a DRS K i = ⟨U i , C i ⟩ and the discourse referents from its universe U i are accessible to an occurrence of a DRS K j if and only if K j is weakly subordinate to K i .

The definition of subordination can be summed up by saying that a DRS subordinates every DRS it contains, and within implications, the antecedent subordinates the consequent. This definition of accessibility is compatible with our translation from DRSs to first-order logic formulas. A discourse referent

x is accessible to a DRS K if and only if the first-order translation of K falls within the scope of the quantifier of x.

Type-Theoretic Dynamic Logic

121

K 0 : K 1 :
x y farmer x donkey y own x y ⇒ K 2 : beat x y

In the above, x and y, the discourse referents of K 1 , are available to K 2 . Therefore, the occurrences of x and y in K 2 are bound. However, x and y are not available to K 0 . This means that if we were to continue the discourse in Example 7 with the sentence he is cruel, we could not interpret the pronoun he as referring to the farmer x since new contributions are evaluated within the main DRS K 0 . This correctly predicts the infelicity of the discourse in Example 9.

(9) * Every farmer 1 who owns a donkey 2 beats it 2 . He 1 is cruel.

Removing Implication and Disjunction

In dynamic logics such as DPL [53] or TTDL [38, 80], implication, disjunction and universal quantification are expressed in terms of conjunction, negation and existential quantification, which are primitive. In DRT, we can do something similar and reduce the ⇒ connective (which plays the role of implication and universal quantification) and the ∨ connective to the other primitives.

x 1 … x n c 1 . . . c m ⇒ K = ¬ x 1 … x n c 1 . . . c m ¬K K 1 ∨ K 2 = ¬ ¬K 1 ¬K 2
In both cases, it is easy to verify that the truth conditions are not affected: applying the (_) fo mapping to both sides of an equation yields equivalent propositions. Similarly, we can verify that the reduction preserves accessibility (i.e. that the set of available discourse referents in an argument to either ⇒ or ∨ does not change). After the reduction, the consequent of the implication is still immediately subordinate to the antecedent. As for disjunction, neither of the disjuncts is subordinate to the other.

Type-Theoretic Dynamic Logic

We end this chapter by reviewing another theory of dynamics which served as a basis for our analysis of anaphora and presupposition in Chapter 7. The theory originates from de Groote's paper on a montagovian treatment of dynamics [38] and it was extended in the dissertations of Lebedeva [80] and Qian [111], where it is referred to as Type-Theoretic Dynamic Logic (TTDL). TTDL aims to reproduce the predictions of DRT and dynamic semantics while using only standard logical tools. Unlike DPL and DRT, there is no need to introduce a new logic with non-standard notions of binding and scope. Meanings are represented as functions and propositions in the simply-typed λ-calculus (i.e. higher-order logic) and their composition does not necessitate the use of any special primitive operator (such as the merge operator on DRSs [99]).

We will start our introduction of TTDL by showing the meaning that is assigned to the two sentences of Example 6 and then we will explain what is going on.

Jones owns a Porsche = λeϕ. ∃x. Porsche x ∧ own j x ∧ ϕ (x :: j :: e)

It fascinates him = λeϕ. fascinate (sel it e) (sel he e) ∧ ϕ e

As we have seen in 5.3, sentences with anaphoric pronouns cannot be given a truth value unless we know the context in which they have been produced. The meanings are therefore functions of their environments, also called (left) contexts. By convention, we use the variable e for these environments. In the denotation for the second sentence, we retrieve the referents of the two anaphoric pronouns from the context e using the functions sel it and sel he . The denotations also need a way to update the context, e.g. when introducing new discourse referents. To enable this, the meanings have access to their continuation (also called a right context), for which we will always use the variable ϕ. In the denotation for the first sentence, we apply this continuation to a context which was updated with the discourse referents j (for Jones) and x (for the Porsche). The nature of the context in TTDL is left open. In [38], the context is taken to be a list of available discourse referents, hence the ML-style syntax for consing the elements x and j to the context e. Finally, in 5.3, we have also seen that when interpreting indefinites with existential quantifiers, we need the scope of the quantifier to extend and cover the meanings of any sentences that follow. The use of continuations allows us to accomplish that. After the denotation of a sentence applies the continuation to the updated context, it can place the resulting proposition under the scope of any existential quantifiers it introduces, as is the case in the denotation of the first sentence.

We will now look at the types involved. As in Church's simple theory of types, there is the o type for propositions and the ι type for individuals. The contexts that sentences have access to are of type γ. The continuations take (updated) contexts as arguments and return propositions which represent the meaning of the following discourse, hence their type is γ → o. Therefore, the type of the denotations that is assigned to sentences in TTDL is γ → (γ → o) → o. This type is abbreviated as Ω and terms of this type are called dynamic propositions. Below, we give the types of the auxiliary operations on contexts.

nil : γ (_ :: _) : ι → γ → γ sel he , sel she , sel it : γ → ι
Existing work on TTDL focuses on discourse representation and composition rather than anaphora resolution. Anaphora resolution is delegated to the sel oracle functions, which are assumed to retrieve the correct antecedent from the environment.

The meanings of the two sentences we have given above are both dynamic propositions. TTDL gives us a way to compose dynamic propositions using the discourse concatenation operator (_ . _):

(_ . _) : Ω → Ω → Ω A . B = λeϕ. A e (λe ′ . B e ′ ϕ)
The left context e of the resulting proposition is passed directly to A. The right context of A contains both the dynamic proposition B and the right context ϕ. The left context passed to B is the updated context e ′ that A passes to its continuation. The right context of B is the right context ϕ of the resulting proposition A . B.

Using the discourse concatenation operator, we can compute the meaning of the discourse from Example 6.

Jones owns a Porsche. It fascinates him.

= Jones owns a Porsche . It fascinates him = λeϕ. ∃x. Porsche x ∧ own j x ∧ fascinate (sel it (x :: j :: e)) (sel he (x :: j :: e)) ∧ ϕ (x :: j :: e) = λeϕ. ∃x. Porsche x ∧ own j x ∧ fascinate x j ∧ ϕ (x :: j :: e)

Type-Theoretic Dynamic Logic 123

In the above, we assume that anaphora resolution will pick up the Porsche x as the antecedent for the pronoun it (i.e. sel it (x::j::e) = x) and Jones, j, as the antecedent for the pronoun him (i.e. sel he (x::j::e) = j).

We can retrieve the truth conditions of the discourse by applying it to some default context (e.g. the nil context which does not make available any discourse referent) and the empty right context (i.e. the continuation λe. ⊤, where ⊤ is a tautology).

static : Ω → o static = λA. A nil (λe. ⊤)
We can define a combinator static which will map dynamic propositions to static ones by interpreting them in the empty context. Applying this combinator to the dynamic proposition that is the meaning of Example 6 gives us the desired truth conditions. static Jones owns a Porsche. It fascinates him. = ∃x. Porsche x ∧ own j x ∧ fascinate x j

Logic

We have seen the notion of a dynamic proposition. In formal logics, propositions are defined as expressions of a formal language which includes logical connectives such as conjunction, disjunction and quantifiers. In her dissertation [80], Lebedeva defines such connectives for TTDL. [START_REF] Pogodalla | Controlling extraction in abstract categorial grammars[END_REF] A ∧ B = λeϕ. A e (λe ′ . B e ′ ϕ)

¬ A = λeϕ. ¬ (A e (λe ′ . ⊤)) ∧ ϕ e ∃ P = λeϕ. ∃x. P x (x :: e) ϕ A → B = ¬ (A ∧ ¬ B) A ∨ B = ¬ (¬ A ∧ ¬ B)
∀ P = ¬ (∃ x. ¬ (P x)) Implication, disjunction and universal quantification are expressed in terms of conjunction, negation and universal quantification, as in DPL (3.4 in [53]) or DRT (Subsection 5.3.4). Dynamic conjunction is the same thing as the discourse concatenation combinator, i.e. we acknowledge the discourse update of both of the conjuncts. Dynamic negation denies the discourse update of the negated proposition by applying it to the empty right context λe ′ . ⊤. Applying the current left context e and the empty right context to the proposition A and then negating it is like interpreting A within its own DRS K and then producing the condition ¬K. The context that is passed to the continuation of the negation is the same context e that the negated proposition received. The dynamic existential quantifier wraps an (ordinary) existential quantifier over the predicate as well as its continuation ϕ. This has the effect of achieving the desired right-extension of existential quantifiers in dynamic semantics (i.e. (∃x. A) ∧ B = (∃x. A ∧ B)). At the same time, it also introduces the variable x into the context as an available discourse referent.

Monadic Structure

Within TTDL, we find the structure of a monad (definition in 3.3.6). The dynamics monad is given by the following functor D and combinators η and ≫=:

D(α) = γ → (α → γ → o) → o η x = λeϕ. ϕ x e X ≫= f = λeϕ. X e (λxe ′ . f x e ′ ϕ) 124

Chapter 5. Introduction to Formal Semantics

These operations satisfy all three of the monad laws. The D monad characterizes computations that have read/write access to some state of type γ and can manipulate their continuation of type o. We can actually derive D as the combination of the state monad and the continuation monad using monad transformers. Let S be the state monad which maps the type α to the type γ → (α×γ). This is the monad that underlies state, such as the storing and retrieving of discourse referents. There exists also a monad transformer S T which maps monads F into monads S(F ) that enrich the structure of F with state. The monad S(F ) maps the type α to the type γ → F (α × γ). Let C be the continuation monad which maps the type α to the type (α → o) → o. By applying the S monad transformer to the C monad, we get a monad S(C) that maps the type α to the type γ → ((α × γ) → o) → o. This type is isomorphic to the type

D(α) = γ → (α → γ → o) → o by currying.
We have presented the D monad. Now, we will show how it features in TTDL. We will focus on the type D(1), i.e. the type of computations that produce no output and where we are only interested in the side effects.

D(1) = γ → (1 → γ → o) → o ≡ γ → (γ → o) → o = Ω
The types D(1) and Ω are isomorphic due to the isomorphism between the types 1 → γ and γ. We can also take the η and ≫= combinators, specialize them to the D(1) type and then apply the 1 → γ ≡ γ isomorphism to simplify them. On the type level, η will end up being a dynamic proposition and ≫= a binary operator on dynamic propositions. On the term level, we find out that η 1 is the dynamic tautology and ≫= 1 is dynamic conjunction.

η : α → D(α) η 1 : 1 → D(
η x = λeϕ. ϕ x e η 1 = λeϕ. ϕ e X ≫= f = λeϕ. X e (λxe ′ . f x e ′ ϕ) X ≫= 1 Y = λeϕ. X e (λe ′ . Y e ′ ϕ)
Furthermore, by verifying the monad laws for D, we have verified the monoid laws for dynamic conjunction with dynamic tautology as the neutral element.

In TTDL, discourse is composed with the discourse concatenation operator, which is just the dynamic conjunction operation. Now we have seen that dynamic conjunction corresponds to monadic composition in the D monad. Therefore, composition of discourse corresponds to composition within the D monad.

Example Lexical Entries

We end our exposition of TTDL by a quick glance at the semantics of a tiny fragment, a subset of the one in [38]. We start by giving the abstract syntactic types to the lexical items in our fragment. Next, we identify the types of interpretations that we will use.

Type-Theoretic Dynamic Logic

S = Ω N = ι → Ω N P = (ι → Ω) → Ω
Sentences will denote dynamic propositions, nouns will denote dynamic properties (functions from individuals to dynamic propositions) and noun phrases will denote dynamic generalized quantifiers (same type as generalized quantifiers but with o replaced with Ω). We can now give a semantics to the lexical items. The first four lexical entries give semantics to noun phrases. These are written as generalized quantifiers: they all abstract over a variable P which defines the scope of the quantifier. Neither the proper noun M nor the pronoun  are quantificational and so they dispose of P by applying it immediately to the individuals that they refer to. However, the proper noun M takes advantage of the continuation P to access the context e and modify it to include the discourse referent for Mary in the following context. Similarly, the pronoun  uses the continuation P to access the context e and find within it a suitable referent. The denotations for the determiners  and  are the same as the ones we have seen in 5.2.3, only the classical logical operators have been replaced with the dynamic ones from 5.4.1. The lexical entry for the common noun  differs in that the proposition woman x had to be raised from a (static) proposition to a dynamic proposition. Finally, we have the lexical entry for the transitive verb . The solution here differs to the one in 5.2.3. The abstract type N P is interpreted as the type of (dynamic) generalized quantifiers, not just individuals. The transitive verb, abstract type N P -•N P -•S, thus has access to the generalized quantifiers of the subject and the object, not just their referents. The entry arranges those two quantifiers so as to always generate a subject-wide scope reading. This restriction is necessary, because arranging the quantifiers in an object-wide scope configuration would make it so that the discourse referents from the object could bind anaphoric elements of the subject, which is not the linguistic reality we want to model. We return to the problem of generating inverse scope while avoiding licensing right-to-left anaphora (cataphora) in 8.5.1.

In 5.4.2, we have seen that the monadic structure underlying TTDL is composed of state manipulation (the state monad -introducing and recovering discourse referents) and continuation manipulation (the continuation monad -scoping existential quantifiers over future discourse). Now we have seen that in the fragment from [38], there is another layer of continuation structure at the level of the noun phrases/generalized quantifiers. In Section 6.4, we will express the continuation-passing style of generalized quantifiers using λ operations and handlers, and in Chapter 7, we will do the same for the state and the continuations at the level of discourse dynamics. Then, in Chapter 8, we will build a grammar that will, among other effects and phenomena, include all of these layers.

Introducing the Effects

In this chapter, we will take a miniature fragment and extend it in different directions, studying various linguistic phenomena. The common point in all of these analyses is that they will all rely on the notion of computations introduced in λ .

We will start by first taking the initial fragment and lifting its usual semantics into the domain of computations (6.1), so that it will be compatible with the development in the following sections. We will then consider the semantics of deictic pronouns (6.2), appositives (6.3) and quantified noun phrases (6.4). After a tour of these analyses, we will take a step back and reflect on the methodological process that underlies their development (6.5).

Lifting Semantics into Computations

Let us start with a very tiny fragment with proper names to name individuals and verbs to act as predicates over these individuals: J, M : N P

 : N P -• N P -• S
In this tiny fragment of proper names and predicates, we could interpret noun phrases as individuals ( N P = ι) and sentences as propositions ( S = o). Provided we have some constants j : ι and m : ι and a predicate love : ι → ι → o, we can give the following semantics to these items: This interpretation works fine for simple sentences such as John loves Mary. However, the denotations that we will assign to noun phrases that are deictic or quantified will not fit into the type ι. Instead, we will interpret these constituents as computations producing individuals, type F E (ι). In order to satisfy the homomorphism property of ACGs and to have a sound syntax-semantics interface, we will need to lift the denotations of these basic constants and predicates into computations. This is very much like the case when one introduces quantified noun phrases and switches to using generalized quantifiers instead of simple individuals as denotations of noun phrases.

We will want linguistic expressions to denote computations. One systematic way to achieve that is to say that the atomic types of our abstract syntactic signature should be interpreted as computations. We will writev for the semantic interpretation using simple values andc for the semantic interpretation using computations. On the type level, we will define a c = F E ( a v ) for atomic abstract types a. By applying this to the common Montagovian interpretation, we get:

S v = o S c = F E (o) N P v = ι N P c = F E (ι) N v = ι → o N c = F E (ι → o)
To lift the denotations of noun phrases from N P v = ι to N P c = F E (ι), it suffices to use η to inject ι inside of F E (ι). This goes the same for any other lexical item whose abstract type is an atomic type. For syntactic constructors that take arguments, such as verbs or adjectives, we will chain the computations of their arguments and apply the meaning of the constructor to the meaning of the results of these computations. We will limit ourselves to syntactic constructors of second-order type, i.e. abstract constants whose type is a 1 -• • • • a n -• b where all a i and b are atomic types. If we use higher-order syntactic constructors, we will give them a bespoke semantics.

lift L α : α v → α c lift L a (x) = η x lift L a-•β (f ) = λX. X ≫= (λx. lift L β (f x))
This particular schema chains the evaluation of its arguments from left-to-right (as can be seen by looking at the expanded non-recursive definition below). While indexicality is order-independent, some of the effects that we will introduce later (such as anaphora) are order-dependent. The order that we would like to reflect in the evaluation is the linear lexical order in which the arguments appear in the spoken/written form of the sentence. Since in categorial grammars of English, it is often the case that operators first take their complements from the right and then apply to their argument on the left (e.g. transitive verbs or relative pronouns of type (N P -•S)-•N -•N ), we will often like to chain the evaluation of the arguments in the order opposite to the one in which we receive them. This will give rise to the lift R operation.

lift L a1-••••-•an-•b (f ) = λX 1 . . . X n . X 1 ≫= (λx 1 . . . . X n ≫= (λx n . η (f x 1 . . . x n ))) lift R a1-••••-•an-•b (f ) = λX 1 . . . X n . X n ≫= (λx n . . . . X 1 ≫= (λx 1 . η (f x 1 . . . x n )))
With these in hand, we can now lift the interpretations of our simple fragment into computations:

Lifting Semantics into Computations

129

J c = lift L N P (j) = η j M c = lift L N P (m) = η m  c = lift R N P -•N P -•S (λos. η (love s o)) = λOS. S ≫= (λs. O ≫= (λo. love s o)) = λOS. love •≫ S ≪•≫ O = λOS. η love ≪•≫ S ≪•≫ O
In the lexical entry for , we can express the series of binds using the application operators from 1.6.1. The idea behind the notation is that you are supposed to put double brackets on a side of the operator whenever the argument on that side is a computation. In our example, S and O are both computations and love is a pure function term. We can expand this term so that it is a bit more regular by making love a computation as well. We can then a notice a connection between the denotations inv and the denotations inc . Thec denotations are just thev denotations where every constant c was replaced with η c and every application f x was replaced with f ≪•≫ x. Note that η and ≪•≫ make up the applicative functor F E (see 3.3.5).

We close this section by proving that adding this computation layer does not affect the predictions that this semantics makes. First, we start with a lemma that will allow us to exploit the fact that we restrict ourselves to second-order types.

Lemma 6.1.1. Second-order terms hide no abstractions

Every β-normal term Γ ⊢ M : τ of second-order type τ in the simply-typed λ-calculus is of the form λx 1 . . . x n . N where N contains no abstractions, provided that any constants used have only a second-order type and any variables present in Γ have a first-order (i.e. atomic) type.

Proof. Let M = λx 1 . . . x n . N where N is not an abstraction (n might be 0). We will need to prove that N contains no abstractions.

We will use proof by contradiction. Let us assume that N contains some abstractions. We order the subterms of N left-to-right, depth-first. Let N ′ = λx. N ′′ be the first abstraction we find in this traversal.

N ′ must be a proper subterm of N since N is known not to be an abstraction.

We now consider the contexts in which N ′ can occur:

• N ′ occurs as the function in an application N ′ A This is in contradiction with M being a β-normal form since we have an abstraction in function position, i.e. a β-redex.

• N ′ occurs as the argument in an application F N ′

We know that F does not contain any abstractions since N ′ is the first abstraction we encountered in the left-to-right ordering of subterms. Furthermore, N ′ is the first abstraction in a depth-first ordering and so the only (free) variables that occur in F are the variables x 1 . . . x n and the variables in Γ, all of which are of first-order type. F is therefore not a variable (since it must have a functional type). F is either a constant or an application. Furthermore, if F is an application, we can apply the same reasoning and by induction conclude that F must be a constant c applied to some n arguments, F = c A 1 . . . A n , with n possibly being 0. However, since c is of second-order type, all of its arguments are of first-order type. This is in contradiction with N ′ being an abstraction.

• N ′ occurs as the body of an abstraction λy. N ′ This is in contradiction with N ′ being the first abstraction we encounter in the depth-first order.

Corollary 6.1.2. Second-order terms are trees

Assuming all constants are of second-order type, every closed term ⊢ M : ν of atomic type ν has a β-normal form c M 1 . . . M n where M i are also closed terms of atomic types.

Proof. From Lemma 6.1.1, we know that the normal form of M is of the shape λx 1 . . . x n . N where N contains no abstraction. Furthermore, we know that M is of an atomic type, therefore n = 0 and the normal form is just N . Since N is closed, it contains no free variables, and since it is abstraction-free, it contains no bound variables either. Note that this is also the case for every subterm of N .

N is composed entirely of constants and applications. If N is an application, then the function is either a constant or some smaller application composed entirely of constants and applications. By induction, we thus show that M 's normal form, N , is of the shape c M 1 . . . M n . Since c has a second-order type, all of its arguments must have a first-order, atomic, type. • there exists some effect signature E such that for every abstract atomic type τ ∈ Σ a , τ c = F E ( τ v )

• for every abstract constant c : τ ∈ Σ a , c c = lift τ ( c v ) where lift is either lift L or lift R107

Then for every closed well-typed abstract term ⊢ Σa M : ν where ν is an atomic abstract type from Σ a , we have:

M c = η ( M v )
Proof. From Corollary 6.1.2, we know that M can be β-converted to a term of the form c M 1 . . . M n where all M i are also closed abstract terms of atomic type. Let a 1 -• . . . a n -• ν be the type of c in Σ a .

We will proceed by induction on the structure of this normal form:

• M = c with c : ν ∈ Σ a
In that case, we have the desired property by definition ofc .

• M = c M 1 . . . M n with n > 0

First, we applyc to M and make use of the induction hypothesis for M i :

c M 1 . . . M n c = c c M 1 c . . . M n c = lift a1-•...an-•ν ( c v ) (η M 1 v ) . . . (η M n v )
If lift is lift L , then:

lift L a1-•...an-•ν ( c v ) (η M 1 v ) . . . (η M n v ) = (λX 1 . . . X n . X 1 ≫= (λx 1 . . . . X n ≫= (λx n . η ( c v x 1 . . . x n )))) (η M 1 v ) . . . (η M n v ) = (η M 1 v ) ≫= (λx 1 . . . . (η M n v ) ≫= (λx n . η ( c v x 1 . . . x n ))) = η ( c v M 1 v . . . M n v ) = η c M 1 . . . M n v
Similarly, if lift is lift R , then:

6.2. Deixis 131 lift R a1-•...an-•ν ( c v ) (η M 1 v ) . . . (η M n v ) = (λX 1 . . . X n . X n ≫= (λx n . . . . X 1 ≫= (λx 1 . η ( c v x 1 . . . x n )))) (η M 1 v ) . . . (η M n v ) = (η M n v ) ≫= (λx n . . . . (η M 1 v ) ≫= (λx 1 . η ( c v x 1 . . . x n ))) = η ( c v M 1 v . . . M n v ) = η c M 1 . . . M n v
Corollary 6.1.4. For every term M in the abstract language of a second-order ACG with an atomic distinguished type S, we have:

M c = η ( M v )

Deixis

The first phenomenon that we will speak about is deixis [81]. Deictic expressions is the class of expressions that depend on the time and place of the utterance, the speaker and the addressee and any kind of pointing/presenting the speaker might be doing to draw the attention of the addressee. These expressions include personal pronouns, temporal expressions, tenses, demonstratives and others. All of these are characterized by their dependence on the extra-linguistic context. In this section, we will restrict our attention to a very limited subset of these expressions: singular first-person pronouns (I, me).

 : N P

The meanings that we assign to expressions in natural languages must reflect this context-sensitivity: the truth conditions of Mary loves me change when it is pronounced by John and when by Peter. Montague [98] achieved this by having the meaning of every expression depend on a point of reference: a pair of a possible world and a moment in time (i.e. the modal where and the when of the utterance). To model first-person pronouns, we will need to have our meanings depend on the identity of the speaker.

In the case of a deictic expression, we have an expression whose referent cannot be determined solely from its form and the meaning of its parts. We will need to reach out into the context and it is for this that we will be using the operations in λ . The first-person pronoun has an interaction with its context, which consists of asking the context for the identity of the speaker. For this kind of interaction with the context, we will introduce an operation symbol, speaker. We will also fix the symbol's input and output types. The input type represents the information and/or the parameters that the denotation of the firstperson pronoun or any other expression necessitating the identity of the speaker will need to provide to the context. Since we have no information or parameter to give to the context, we will use the trivial input type 1, whose only value is ⋆. The output type represents the information that the context will provide us in return. We are interested in the identity of the speaker and so the type of this information will be the type of individuals, ι.

We can now model the meaning of a first-person pronoun as a computation of type F E (ι) that interacts with the context and produces a referent of type ι. The effect signature E can be any signature provided that speaker : 1 ↣ ι ∈ E.

 = speaker ⋆ (λx. η x) = speaker! ⋆
The denotation of  demands the context for the identity of the speaker x using the operation speaker and then declares that x to be its. Taking the output of an operation and then immediately returning it as the result of the computation will be a common pattern and so we use the speaker! shorthand introduced in 1.6.2. Now the question is how to use the denotation given above to build meanings of sentences containing first-person pronouns, e.g. Mary loves me. In Montague's use of points of reference, Montague introduces an intermediate language of intensional logic [98]. When Montague then gives an interpretation to this language, the point of reference at which an expression is to be evaluated is passed through to its subexpressions. We will be making use of the lifted semantics introduced in the previous section. The chaining of the computations will serve our purpose of propagating the indexicality of the noun phrase to the sentence containing it (or vice versa, the propagation of the sentence's speaker to the noun phrase contained within).

With the interpretations given before, we can now analyse the following sentences:

(10) John loves Mary.

(11) John loves me.

whose meanings we can calculate as:

 M J ↠ η (love j m) (10)
  J ↠ speaker ⋆ (λx. η (love j x))

For (10), we get a pure computation that produces the proposition love j m, which is the same proposition that the sentence denoted before we modified the fragment to use computations. However, in the case of (11), we do not have any single proposition as the denotation. Instead, we have a request to identify the speaker of the utterance and then we have a different proposition love j x for each possible speaker x. The truth conditions of this sentence can only be found by considering some hypothetical speaker s. Given such a speaker, we could resolve all of the requests for the speaker's identity and since our effect signature E does not contain any other operations, arrive at the desired truth conditions. This function that will interpret the speaker operation symbols will be a handler.

withSpeaker : ι → F {speaker:1↣ι}⊎E (α) → F E (α) withSpeaker = λs. speaker: (λ_k. k s) [START_REF] Potts | The logic of conventional implicatures[END_REF] The type tells us that withSpeaker s is a handler for the speaker operation. It takes any computation of type F {speaker:1↣ι}⊎E (α) and gives back a computation of type F E (α), in which speaker will not be used. Since speaker is the only operation in our effect signature, by applying this handler to the denotation of a sentence in our fragment, we get a denotation of type F ∅ (o), which is isomorphic to o. [START_REF] Potts | The dimensions of quotation. Direct compositionality[END_REF] withSpeaker s   J ↠ η (love j s)

Quotations

Up to now, we could have assumed that at the object level, we have a constant speaker standing in for the speaker. After adding a constant to our logical signature, our new models would have interpretations for symbols in the original signature and for the speaker constant, i.e. our models would become descriptions of the world paired with some deictic index. However, removing the notion of a context and making the speaker be a part of the model would make it difficult to analyze the difference between the following two sentences: (12) John said Mary loves me. [START_REF] Potts | The logic of conventional implicatures[END_REF] We will be using _ as the name of a variable whose value we are not interested in. Such a variable will always have the trivial type 1. [START_REF] Potts | The dimensions of quotation. Direct compositionality[END_REF] The two directions of the isomorphism are given by -• : F ∅ (α) → α and η : α → F ∅ (α).

Deixis

133

(13) John said "Mary loves me".

In our setting, we can model this kind of behavior since the withSpeaker handler is not a meta-level operation, but it is a term in our calculus like any other. We can therefore have lexical entries for direct and indirect speech that will interact differently with deictic expressions. The indirect speech use of said has the same kind of lexical entry as the transitive verb loves. In the direct speech entry, we would like to bind the speaker within the complement clause to the referent of the subject. We will therefore want to wrap the complement clause in a handler for speaker. However, the handler (withSpeaker s) needs to know the referent s of the subject S. We will need to first evaluate S and bind its result to s. To highlight the fact that the two entries differ only in the use of the (withSpeaker s) handler, we have expanded the entry for indirect speech into the same form. Also note that in this solution, we have had to use ≫= and we cannot get by with only η and ≪•≫ (i.e. we need not only an applicative functor, but also a monad).

We can now plug this new entry in and compute the meanings of Examples 12 and 13.

  (  M) J ↠ speaker ⋆ (λx. η (say j (love m x)))

  (  M) J ↠ η (say j (love m j))

In (12), the speaker operation projects outside the complement clause and we end up with another speaker-dependent proposition. On the other hand, in (13), the dependence on the identity of the speaker has been discharged by the handler contained in the denotation of   .

Algebraic Considerations

One of the traditions from which the technique of effects and handlers originates is the study of algebraic effects by Plotkin, Power, Pretnar and Hyland [60, 103, 110, 104]. The semantics of a system of operations is not given by handlers but by a system of equations. Instead of writing a handler which would interpret two computations as the same object, we would give equations that let us prove the two computations equivalent. This perspective can give us some insights.

Assuming that the speaker operation is only ever handled by the withSpeaker handler, the following equations become admissible:

speaker ⋆ (λx. speaker ⋆ (λy. M (x, y))) = speaker ⋆ (λx. M (x, x)) M = speaker ⋆ (λx. M )
M is a metavariable ranging over computations of type F {speaker:1↣ι} (α). [START_REF] Qian | Accessibility of Referents in Discourse Semantics[END_REF] We can check by reduction that whenever M 1 = M 2 via the above equations, then (withSpeaker s M 1 ) and (withSpeaker s M 2 ) are 134 Chapter 6. Introducing the Effects convertible in λ . The insight we get from these equations is that asking for the speaker is an idempotent operation: if we ask twice within the same computation, we are guaranteed to get the same answer. It also tells us that asking for the speaker has no other effect than to make available the identity of the speaker: we can add a request for the current speaker and if we do not use the answer, this addition will not change anything.

The motivation behind the choice of exactly these two equations is normalization. Denotations in F {speaker:1↣ι} (α) are formed by a series of speaker operations followed by a value of type α. We can use the first equation to collapse all of the speaker operations into one, or if there were no speaker operations we can use the second equation to include one. This means that we can see every value of type F {speaker:1↣ι} (α) as being equal to one which is of the shape speaker ⋆ (λx. η (M (x))), i.e. a family which to every x : ι assigns an M (x) : α. This connects us back to the treatment of deixis in Montague's approach [98] where meanings are functions which assign to every point of reference x some referent M (x). This normalization is implemented by the withSpeaker handler. If we flip its arguments, getting (λM s. withSpeaker s M ), we get a function of type F {speaker:1↣ι} (α) → (ι → α).

Conventional Implicature

We have seen an example of an expression asking the context for some missing information. We will now look at a phenomenon which incurs communication in the opposite direction. Conventional implicatures [108] are parts of the entailed meaning which are not at-issue, i.e. are not being asserted, simply mentioned. One of the distinguishing signs is that they project out of logical contexts such as negation, disjunction or implication. Typical examples include supplements such as nominal appositives and supplementary relative clauses, and expressives such as epithets.

Here, we will deal with supplements, namely nominal appositives and supplementary relative clauses. We will assume abstract constants for the (supplementary) relative pronoun, the appositive construction and a relational noun [START_REF] Roberts | Modal subordination and pronominal anaphora in discourse[END_REF] with the following types: The point of our modeling is to show that the conventional implicatures engendered by the supplements project out of all sorts of logical contexts. We will therefore also consider a fragment that contains syntactic constructions for negation ("it is not the case that X"), implication ("if X, then Y") and disjunction ("either X, or Y").

--

: S -• S - : S -• S -• S - : S -• S -• S
In our fragment, a noun phrase contributes both its referent and also possibly some conventional implicature. If we would model this fact by interpreting NPs as pairs of referents and conventional implicatures, we would be forced to revisit all the other lexical entries to take this change into account (e.g. transitive verbs such as  would need to explicitly aggregate the conventional implicatures of both their subjects and objects). Rather than do that, we will make use of λ and model this interaction with the context as an operation. When a linguistic expression wants to conventionally implicate something, it will use the implicate operation. The expression will need to communicate what exactly it wants to conventionally implicate. This will be a proposition and so the input type of implicate will be the type o of propositions. We do not need to collect any information from the context and so the output type [START_REF] Roberts | Modal subordination and pronominal anaphora in discourse[END_REF] We are working in a minimal fragment without determiners. Relational nouns will let us use some meaningful noun phrases as nominal appositives in the examples to come.

Conventional Implicature

135 will be 1. Using this operation, we can now give denotations to expressions that generate conventional implicatures:   = λCX. X ≫= (λx.

C (η x) ≫= (λi. implicate i (λ_. η x)))  = λY X. X ≫= (λx. Y ≫= (λy. implicate (x = y) (λ_. η x))) - = λX. best-friend •≫ X
In both of the supplement constructions, we first evaluate the head NP X to get its referent x. We use x twice: once to construct the conventional implicature and once to produce the referent of the entire complex noun phrase. The conventional implicature constructed by the relative clause is the clause with its gap filled in by an expression that refers to the same referent as the head noun X. The conventional implicature of the appositive is a statement of equality between the referents of the two noun phrases. Finally, we also give the semantics to the relational noun "X's best friend" by assuming that we have a function best-friend : ι → ι in the model.

We will want to show that these denotations project through the operators that make up the logical structure of a sentence/discourse. Since the conventional implicature mechanism is implemented using operations, we can get this behavior for free by just using the standard operators and lifting them to computations.

--

= lift L S-•S (¬) = λX. ¬ •≫ X - = lift L S-•S-•S (→) = λXY. X ≪ → ≫ Y - = lift L S-•S-•S (∨) = λXY. X ≪∨≫ Y
We can now look at several examples of conventional implicatures buried inside logical operators: (14) Either John loves Sarah, or Mary, John's best friend, loves John.

(15) If it is not the case that John, whom Sarah loves, loves Sarah then Mary loves John.

We expect Example 14 to conventionally implicate that Mary is John's best friend and Example 15 to conventionally implicate that Sarah loves John. If we compute their denotations, we find out that these actually are the propositions that the two sentences try to implicate.

- ( S J) ( J ( (- J) M))

↠ implicate (m = best-friend j) (λ_. η (love j s ∨ love m j)) (14) - (-- ( S (  (λx.  x S) J))) ( J M) ↠ implicate (love s j) (λ_. η (¬(love j s) → love m j)) (15) To go full circle and fulfill the empirical criterion that the meaning of Example 14 should entail that Mary is John's best friend, we will need to translate the term containing implicate operations into a proposition. This will be another question of interpreting operation symbols and so we will use a handler. some logical material ∀x. man x → k x that is to scope over the enclosing context k and a placeholder NP denotation η x for some variable x. This is very much like Cooper storage [32]. We store the request to scope certain material over the sentence and we keep a variable as a placeholder denotation for the NP. Before we proceed to explain this fragment any further, we will consider the following example: (16) Every man loves a woman. and its denotation:

 ( ) ( ) ↠ scope (λk. ∀x. man x → k x) (λx.
scope (λk. ∃y. woman y ∧ k y) (λy.

η (love x y))) (16)
We have η (love x y) as the core meaning, with both (λk. ∀x. man x → k x) and (λk. ∃y. woman y ∧k y) scheduled to scope over it. We see that as in Cooper's approach, the scope material that we stored using the NPs gets propagated to the meaning of the entire sentence. Now we need an analogue to Cooper's retrieval procedure that can take this scope material and apply it to the meaning of the nucleus. This role is carried out by the handler SI, short for Scope Island.

SI  ( ) ( )

↠ ∀x. man x → (∃y. woman y ∧ love x y)

The handler SI will also end up being part of our denotations. Quantifiers can only take scope up to the limit of the nearest enclosing scope island and that is a constraint that we can encode using this handler. We could, for example, implement the constraint that tensed clauses should form scope islands by including the SI handler in the denotations of the constructors of tensed clauses.

 = λOS. (η • SI) (love •≫ S ≪•≫ O)
Here, we apply not only SI, but η • SI, to the sentence denotation. This is because our type for interpreting sentences, S , is F E (o) and since in this section, we are using a closed handler (type F E (o) → o), we have to follow with the injection η (type o → F E (o)). [START_REF] Shan | Delimited continuations in natural language: Quantification and polarity sensitivity[END_REF] Using this new lexical entry for , we can directly compute a reading for Example 16:

 ( ) ( ) ↠ η (∀x. man x → (∃y. woman y ∧ love x y)) (16)
Finally, we will address the use of SI in the denotations of  and . We will note that we interpret constituents of type N with the type F E (ι → o). However, in the fragment so far, we have only seen pure nouns, nouns whose denotation is of the form η M . Nevertheless, we can imagine complex constituents of type N which do have a quantificational effect (e.g. owner of a cat).

- :

N P -• N - = lift L N P -•N (λyx. own x y) = λY. Y ≫= (λy. η (λx. own x y))
The relational noun owner does not contribute any quantificational effect, but the complex noun owner of Y inherits any effects of Y . We will see this in the denotation of owner of a cat:

- ( )

↠ - (scope (λk. ∃y. cat y ∧ k y) (λy. η y)) ↠ (λyx. own x y) •≫ (scope (λk. ∃y. cat y ∧ k y) (λy. η y)) ↠ scope (λk. ∃y. cat y ∧ k y) (λy.

η ((λyx. own x y) y))

→ β scope (λk. ∃y. cat y ∧ k y) (λy.

η (λx. own x y))

We can look at the result through the analogy to Cooper storage. We started with the meaning of a cat, which stored the generalized quantifier λk. ∃y. cat y ∧ k y in the storage and whose semantic placeholder was the variable y. We then applied the function λyx. own x y to this semantic placeholder and we arrived at λx. own x y with the storage still holding the quantifier λk. ∃y. cat y ∧ k y.

And so we have seen that constituents of type N can have a quantificational effect in much the same way as other constituents, such as those of type N P . In the generalized quantifier for indefinites, (λk. ∃y. n y ∧ k y), we make use of the meaning n of the restrictor noun. By looking at the type of scope : ((ι → o) → o) ↣ ι, we see that we cannot pass a computation with quantificational effects as an argument to scope. [START_REF] Shan | Linguistic side effects[END_REF] So instead, we discharge the quantificational potential of the noun in the restrictor of the generalized quantifier using the SI handler. [START_REF] Shan | Linguistic side effects[END_REF] We will look at the kind of readings this leads to by considering the classic example from [23]: (17) Every owner of a siamese cat loves a therapist.

Assuming the inclusion of the common nouns siamese cat and therapist in our fragment (with semantics analogous to the ones for man and woman), we can compute the following interpretation:  ( ) ( (- ( -)))

↠ η (∀x. (∃y. siamese-cat y ∧ own x y) → (∃z. therapist z ∧ love x z)) (17)

Quantifier Ambiguity

The lexical entry that we have considered for the determiner every117 so far was:

 = λN. scope! (λk. ∀x. (SI (N ≪• x)) → k x)
However, had we followed the analogy to shift and reset (i.e. wrapping the entire body of the function that is the argument to scope/shift0 in SI/reset, see Section 4.5), we might have tried the following:

' = λN. scope! (λk. SI (N ≫= (λn. η (∀x. n x → k x))))
Here, we put the SI handler above the quantifier introduced by the semantics of the determiner. For reasons of readability, we have also pulled the only impure part, N , in front of the expression using the ≫= operator. This lexical entry puts the scope of any quantifiers found in the restrictor noun over the 140 Chapter 6. Introducing the Effects scope of the quantifier contribued by the determiner. If we try using this lexical entry when computing the meaning of Example 17, we find another possible reading:  ( ) (' (- ( -)))

↠ η (∃y. siamese-cat y ∧ (∀x. own x y → (∃z. therapist z ∧ love x z)))

Both of the readings we have seen are actually valid interpretations of this sentence; quantifiers are a notorious source of ambiguities. We could include both  and ' in our grammar, one giving narrow scope to resrictor quantifiers and the other giving them wide scope (the same would be the case for other determiners such as ). This way, both readings would be available.

Note that Example 16 is ambiguous as well. The existential quantifier in a woman can take either wide or narrow scope (we call it wide scope when the object quantifier scopes over the subject quantifier and we call it narrow when it scopes under). The relative scope of the quantifiers is given by the order in which they appear in the computation: to get the object in wide scope, we would need to chain the computations of the subject and object by putting object first, subject last.

 = λOS. (η • SI) (love •≫ S ≪•≫ O) = λOS. (η • SI) (S
' ( ) (' (- ( -)))

↠ η (∃z. therapist z ∧ (∃y. siamese-cat y ∧ (∀x. own x y → love x z)))

However, Example 17 has one more reading that we will not be able to get at using this technique.

∃y. siamese-cat y ∧ (∃z. therapist z ∧ (∀x. own x y → love x z))

This reading is equivalent to the last reading, ' ( ) (' (- ( -))) . The only difference is that this time, a siamese cat has scope over a therapist. This distinction would be important in sentences involving a different quantifier then the existential coming from the indefinite, such as in the sentence "Every researcher of a company saw most samples" [23]. In our fragment, we cannot reproduce this reading because the order in which the quantifiers take place goes like this: a siamese cat from the subject, a therapist from the object and every owner from the subject. However, we have no simple way to crack open the chain of quantifications from the subject and insert the quantification from the object in the middle. We will therefore turn to a more robust and elegant solution which will get us the readings we want and will not profilerate duplicate entries such as /' and /'.

Quantifier Raising

We will make use of the fact that ACGs are a categorial grammar formalism and their syntactic structures are not just constituency trees, but derivations which can use hypothetical reasoning. That is to say, the terms in the abstract signature which represent the tectogrammatic structure can contain λ-binders and variables. We will use this to implement Montague's treatment of quantifiers [98], called "quantifying in" or "quantifier raising". [START_REF] Shan | A static simulation of dynamic delimited control[END_REF] Montague's technique can be explained by saying that sentences such as "every man loves a woman" can be paraphrased as "a woman, every man loves her". The quantifier that is to be raised is replaced by a pronoun/variable. Later, we use a construction that lets us form a sentence by combining a noun phrase with a sentence in which a variable is to be bound. We can licence this kind of construction in our ACG by adding the following (unlexicalised) abstract constant:

QR : N P -• (N P -• S) -• S QR = λXK. X ≫= (λx. K (η x))
The type of QR can also be read as a kind of type-lifting operator on NPs: it takes an N P and gives back an (N P -•S)-•S (the syntactic type for quantified noun phrases used in [105]). As for the semantics, we can regard it as a variation on the term λXK. K X: instead of passing X directly to K though, we first evaluate it to get its referent x and then we pass to K a trivial computation that always this referent x.

We will demonstrate QR by deriving the object wide scope reading of Example 16:

SI (QR ( ) (λy.  y ( )))
↠ SI (scope (λk. ∃y. woman y ∧ k y) (λy. ∀x. η (man x → love x y))) ↠ (λk. ∃y. woman y ∧ k y) (λy. ∀x. man x → love x y)

↠ ∃y. woman y ∧ (∀x. man x → love x y)

We can also generate all five readings of Example 17, without incurring the overgeneration due to Cooper's storage [23] thanks to the ACG type system. [START_REF] Shan | The character of quotation[END_REF]



The QR operator allows us to displace the scope of any quantifier. [START_REF] Shan | Explaining crossover and superiority as left-to-right evaluation[END_REF] We might now risk overgenerating by letting quantifiers leak outside of scope islands. However, this can be remedied at the level of the abstract type signature. Pogodalla and Pompigne [106] show how to use dependent types in the abstract signature of an ACG to enforce a scope island constraint -namely that quantified noun phrases should not take scope outside of the nearest enclosing tensed clause.

Algebraic Considerations

Unlike deixis and conventional implicature, we will not derive many useful admissible equations for scope. If we try to collapse two uses of scope into a single one, we can succeed only partially:

scope F 1 (λx. scope F 2 (λy. M (x, y))) = scope (λk. F 1 (λx. F 2 (λy. k ⟨x, y⟩))) (λ ⟨x, y⟩ . M (x, y))
We can compose the two quantifiers F 1 and F 2 , but then we are quantifying over pairs of individuals ⟨x, y⟩, which is not something that we have planned to do with scope, whose output type is ι, the type of (single) individuals. Therefore, the above would not even type-check correctly. However, we can derive an equation which shows us how pure computations that yield individuals correspond to computations using scope.

η M = scope! (λk. k M )
M ranges over values of type ι. This equation shows us why, in λ , we are not obliged to raise the denotations of our non-quantified noun phrases (such as the proper names J and M) into generalized quantifiers: the pure individuals η j and η m behave exactly the same as the generalized quantifiers λk. k j and λk. k m, respectively. This means that a sentence can mix the lexical entries for proper nouns from 6.1 with the new lexical entries for quantified noun phrases from this section in a sound way, without violating the homomorphism property of the ACG. ( 18) John loves a man.

 ( ) J ↠ η (∃x. man x ∧ love j x) (18)
Since we do not have any useful laws to simplify the denotations in F {scope:((ι→o)→o)↣ι} (α), the canonical representations will be a hierarchy of generalized quantifiers, one scoping over the other, with a value of type α at the bottom. Previously, we have drawn an analogy to Cooper storage. However, in Cooper storage, the quantifiers are not stored hierarchically, but side-by-side, so that any quantifier can be retrieved. However, this can lead to generating undesired meanings in which variables escape from the scopes of their intended binders. Our approach is closer to Keller storage [66], also known as nested Cooper storage. In Keller storage, quantifiers can be stored both side-by-side and embedded: any of the quantifiers stored side-by-side can be retrieved, but whenever a quantifier is retrieved, all of its embedded quantifiers are retrieved at the same time. Our representation lacks the side-by-side mode of composition. The chain of scope operations in an F {scope:((ι→o)→o)↣ι} (α) denotation corresponds to a series of embedded quantifiers in Keller storage: we cannot retrieve a quantifier without first retrieving the quantifiers which precede it in the chain. This is exemplified by this chain from Example 17 where the y in the second quantifier is bound by the first quantifier: scope (λk. ∃y. cat y ∧ k y) (λy. scope (λk. ∀x. own x y → k x) (λx.

η x))

This means that our representation behaves like Keller storage in that it prevents scope extrusion (variables escaping out of the scope of their intended binders). However, it lacks the basic feature of Cooper (and Keller) storage that is the side-by-side storing of quantifiers to enable ambiguity. In 6.4.1, we have dealt with the ambiguity issue by use of Montague's "quantifying in".

Methodology

We will now take a step back and identify the methodology we have used to analyse these three phenomena: deixis, conventional implicature and quantification.

Using Computation Types

At the basis of any linguistic modelling that uses λ is the notion of a computation: all of the extensions to the simply-typed λ-calculus in λ deal with computation types, types of the form F E (α). We will want to use computations in the semantic interpretations of our lexical items.

If we start from some existing Montagovian semantics (interpreting sentences as propositions, noun phrases as individuals, nouns as sets), there is a question of where to introduce the computation types. In our approach, we choose to make the interpretation of every atomic abstract type a computation. This has roughly the effect of making every constituent a computation. Kiselyov' Applicative Abstract Categorial Grammars [68, 69] use exactly the same strategy, and Barker's continuization approach [12], which replaces the NP interpretation type ι with a "computation type" (ι → o) → o, uses a similar approach. Other possible strategies include:

• Turning every atomic semantic type (ι, o, …) into a computation This idea is well-established in formal semantics. Examples include de Groote's montagovian treatment of anaphora [38] (o is replaced with γ → (γ → o) → o), Lebedeva's extension of this formalism [80] (furthermore replaces ι with γ → ι), Ben-Avi and Winter's [18] intensionalization procedure (replaces o with σ → o) and de Groote and Kanazawa's variation [40] (also replaces ι with σ → ι). We can contrast this approach to ours. Letbe some interpretation of the atomic abstract types. Our strategy leads us to the interpretationc with:

α -• β c = α c → β c ν c = F E ( ν )
α -• β c is the homomorphic interpretation of an ACG type. The interpretations of the atomic abstract types are wrapped in the functor F E .

With the intensionalization procedure of de Groote and Kanazawa [40], we have:

α -• β i = α i → β i ν i = ν α → β = α → β ν = σ → ν
Again,i is an ACG type homomorphism. The interpretations of the atomic types are passed through another type homomorphism, which traverses the structure of the object (semantic) type.

The atomic semantic types are then wrapped in the functor F (α) = σ → α, where σ is the type of possible worlds.

• Turning every semantic function type α → β into the type α → F E (β)

This corresponds to interpreting a call-by-value language using the monad F E [95, 133]. Techniques that use a call-by-value impure language for their semantic entries fall in this category as well. Examples include Shan's use of shift and reset [114, 115] and our previous attempts [89] using the Eff language [16].

• Turning every semantic function type α → β into the type

F E (α) → F E (β)
This is very similar to the idea above but instead of call-by-value, it lets us get a call-by-name interpretation. Call-by-name side effects in natural language semantics have been proposed by Kiselyov [67].

This palette of strategies ranges the possibility space, offering a tradeoff between flexibility and simplicity. Inserting computations into more and more places gives us more expressivity but this comes at the price of the system's simplicity:

• A noun denotation of type F E (ι → o) has some effect and then yields a pure predicate of type ι → o.

• A noun denotation of type ι → F E (o) might have different effects, depending on the semantic argument that it will be applied to. As a consequence, this effect becomes available only when we apply the denotation to some argument of type ι. [START_REF] Sitaram | Handling control[END_REF] • A noun denotation of type F E (ι) → F E (o) might evaluate its argument first, or it might perform some other effects, or it might handle some of the operations used in the computation of its argument.

Furthermore, in a calculus such as λ , where the order of evaluation is controlled manually using monadic combinators, having an overabundance of computation types clouds the terms with uninteresting plumbing and enlarges the possibility space to a point that facilitates ad hoc solutions. In the analyses presented in this manuscript, we have found that the simplest strategy which is sufficiently expressive for our purposes is the one which introduces a computation type into the interpretation of every atomic abstract type [START_REF] Sitaram | Teach yourself scheme in fixnum days[END_REF] and so we stick with this strategy throughout the whole manuscript. However, the techniques developed here can be also used in the other settings.

Choosing the Return Types and Seeding a Grammar

We can now take some base grammar that will serve as our starting point in investigating some phenomenon. In our case, we consider one of the smallest fragments imaginable: transitive verbs and names. We presuppose a semantics for this fragment that uses computations. We either build it from scratch or we lift an existing semantics as we did in 6.1. Our base semantics is very simple, it does not use generalized quantifiers or dynamic logics, since we can treat these phenomena using effects. Again, we use the simplest possible types for the return types of the computations. For example for noun phrases, we do not use generalized quantifiers, since we can do quantification as an effect, we use computations that yield individuals (F E (ι) instead of F E ((ι → o) → o)). We cannot go simpler than that since verbs still need to know what the referents of their subjects and objects are, to what their predicates should be applied. Similarly for sentences, we will use simple propositions instead of dynamic propositions since we will treat dynamicity as an effect (F E (o) instead of F E (γ → (γ → o) → o)). Again, it might seem that a proposition is the bare minimum that a sentence must denote because that is the product that we are interested in. However, in analyses of dynamic semantics, it might make sense to model sentences as having no referent, only side effects that contribute to some knowledge base (see 7.2.4).

Digression: Call-by-Name and Call-by-Value

We have mentioned the possible use of call-by-name and call-by-value. Our approach is more conservative. We do not assume that a single strategy will always suffice and we wire up the evaluation order manually using operators like ≫=. Nevertheless, we can still find some regularity in how we treat evaluation order. Syntactic functions (e.g. movement) are call-by-name and semantic functions (e.g. predicates) are call-by-value. By syntactic function, we mean a function of type α -• β at the abstract level which was mapped by the homomorphismto the object-level function α → β. A semantic function is any other function present at the object (semantic) level, e.g. the predicate love : ι → ι → o.

We will demonstrate this on Example 16: every man loves a woman. [START_REF] Sitaram | Handling control[END_REF] We could use the C operator of λ to get a value of the above type F E (ι → o). However, this partial operation succeeds only if the effects do not actually depend on the argument. If that is the case, we might as well use F E (ι → o) directly. [START_REF] Sitaram | Teach yourself scheme in fixnum days[END_REF] With some caveats when dealing with restrictive relative clauses and presuppositions (see 8.6)

Methodology

145

 ( ) ( ) = (λOS. (η • SI) (love •≫ S ≪•≫ O))     ↠ η (SI (love •≫   ≪•≫   ))
We pass the computations   and   to the lexical entry for the transitive verb  : N P -• N P -• S intact, without forcing their evaluation using ≫= or other operators. Once inside the transitive verb, we apply to them the predicate love. This time, we use the •≫ and ≪•≫ which first evaluate both arguments left-to-right and pass the results to love. All of this happens in the scope of SI, so any quantification that takes place in the verb's arguments is resolved. If we were to simulate callby-value in the outer application (evaluating the meanings of   and   and then passing the results to the meaning of  : N P -• N P -• S), we would have the two arguments evaluated in the opposite order and both of them escaping the scope island we set up in the verb's lexical entry.

(λOS. (η • SI) (η (love S O))) •≫   ≪•≫   ↠   ≫= (λo.   ≫= (λs. η (SI (η (love s o))))) ↠   ≫= (λo.   ≫= (λs. η (love s o)))
Since quantifiers are known to have ambiguous scope and the strength to leave scope islands under certain conditions, this reading might still be acceptable, even though it was not what our lexical entry intended to do (the SI handler had no effect at all). We can look at another example, Example 13: John said "Mary loves me". Here we perform the application of the lexical entry of   : S -•N P -•S in a call-by-name manner. The computation   M gets evaluated only in the scope of the withSpeaker handler. On the other hand, the predicate say : ι → o → o is applied to these computations in a call-by-value manner, forcing their evaluation down to their referents, j and love m j.

If we were to perform a call-by-value application already when applying the lexical entry for   :

S -• N P -• S to the meanings of its arguments, we would end up binding the first-person pronoun not to John, but to the speaker of the utterance. When looking at a term like  ( ) ( ), we might intuitively picture it as the tree in Figure 6.1a. If we wrap the denotation of the sentence produced by a transitive verb in a handler such as SI, we would expect the handler to apply to any operations that would be triggered by the subject or the object. However, if we look at the actual syntactic tree of that term (Figure 6 and the object are not dominated by the transitive verb. If we would use call-by-value evaluation, their effects would not be captured by any handler inside the verb's lexical entry. That is why we perform these applications with call-by-name, moving the computations which are the denotations of the subject and the object inside the lexical entry for the transitive verb. The idea is that the structure of the sentence corresponds to the third tree in Figure 6.1c and we want to treat  as a handler and   and   as expressions having effects. Call-by-name takes care of plugging in the holes and moving the computations into the correct place (under the scope of the correct handlers, in the correct order) and that is why we use call-by-name for syntactic functions α -• β.

If we find out that we always adhere to this rule, we can go further. We could introduce an impure language with algebraic effects (or use an existing one like λ eff [63] or Eff [16]) and translate it to λ in the same way that we translated λ shift and λ shift0 in Chapter 4. The translation would take care of managing the computation types and ordering evaluation, freeing our hands from having to distinguish the types α and F E (α) and having to use ≫= to dictate evaluation order. As we have seen above, the language would need to have both call-by-name and call-by-value abstractions (much like the language proposed by Kiselyov in [67]). In our previous attempt, we used a language without call-by-name abstractions and had to resort to wrapping expressions in thunks. In this manuscript, we found the order in which computations are evaluated too important to be handled by a translation hidden behind the calculus and we prefer to use explicit constructions such as ≫= and computation types to make the evaluation explicit.

Choosing an Effect Signature

We have a simple grammar using computations in some principled way. We are ready to start introducing computations which actually do something and the reason we want to do that is to analyse phenomena which would otherwise defy compositionality. The workflow that we follow goes like this:

1. Choose a suitable effect signature This means identifying the operations that we will be using to implement the phenomenon, what their meaning should be, what input and output types they should have.

Introduce the operations in the lexical entries

If we designed the operations correctly, we should be able to give meanings to lexical items that exhibit the phenomenon that we are studying.

Write handlers for the new operations

Finally, we formalize the meaning of the new operations by writing handlers that interpret them in more basic terms. These handlers can then also be parts of lexical entries.

The first step is the most important. Having found the right set of operations, their use is usually straightforward. An effect signature is validated by writing handlers that give the desired semantics to computations that use the new operations. There are two processes that we follow in order to find the correct effect signature. We will give guidelines on how to use both.

Identifying the Interactions with the Context

Imagine that we are studying some non-compositional phenomenon. Let us remind ourselves of the definition of compositionality: the meaning of a complex expression is determined by its structure and the meanings of its constituents [124] (and nothing else). For meaning to be non-compositional is for meaning to depend on something that is not one of the above. If the meaning depends on something which is not part of the expression itself at all, we call that something the context.

If the meaning depends on some part of the context which can be represented with objects of type β, then we will introduce an operation with output type β. If there are multiple such parts of the context and the meaning needs to identify which one it depends on, the operation will have input type α, where α is the type of the object used to identify the part of the context we are interested in. If there is no need to identify a part of the context, we will use the trivial input type 1. Operations such as this can be though of as getters or consumers, their purpose is to retrieve something from the context.

Examples:

• Deixis, in particular first-person pronouns.

A first-person pronoun is an atomic expression: it has no constituents (not counting case markers). Therefore its meaning cannot really depend on anything and would have to be fixed. However, the referent of the first-person pronoun varies from speaker to speaker. We want the first-person pronoun to designate the speaker, which is part of the context. The speaker is an individual (an entity) and so we will use an operation of output type ι. We assume that there is always at most a single entity which can be identified as the speaker of the utterance and so choose the input type 1. This gives us an operation of type 1 ↣ ι, same as the operation speaker that we have used in 6.2.

speaker : 1 ↣ ι

• Anaphora, such as in third-person pronouns.

A third-person pronoun is also an atomic expression whose referent varies from situation to situation. Its referent depends on the individuals which are currently under discussion. Out of all such individuals, the pronoun needs the identity of the most salient one. We can therefore choose the output type of our operation to be ι. At any time, we could have mutliple salient individuals as candidate answers. The right answer will depend on which third-person pronoun we have used (gender and number). Thus we choose µ × ν as the input type, where µ is the type of grammatical genders and ν is the type of grammatical numbers.

select : µ × ν ↣ ι • Definite descriptions.
A definite description serves to designate an individual. It is composed of the article the and a noun, the meaning of which is a set of individuals. For example, the lazy cat should designate some contextually salient member of the set of lazy cats. Without recourse to context, we do not know which individual to choose and we will therefore use an operation. What we ask for from the context is an individual and so the output type will be ι once more. Contrary to pronouns, we are not looking for just any salient individual but a salient individual that belongs to some specific set (the set of lazy cats in our example). Therefore, we will choose ι → o as the input type of the operation.

find

: (ι → o) ↣ ι • Possible worlds.
This one is similar to deixis. If we are working with modal operators such as might or must without using a modal logic, i.e. by quantifying over possible worlds and parameterizing predicates by possible worlds, then we will often need to access the current salient world. In order to know the meaning of the noun lazy cat, i.e. the set of lazy cats, we will need to know w.r.t. which world we are speaking since different cats are lazy in different worlds. Similarly when we deal with verbs, we will need to know the current world to know whether or not entities are in some relation together.

The information we want from the context is the current salient world. If σ is the type of possible worlds, we will introduce an operation of output type σ. There is no need to specify which current salient world we mean and so we leave the input type at 1.

world : 1 ↣ σ

We have examined the case of the expression's meaning being dependent on something which is not part of the expression itself. Note that this is not the only source of non-compositionality. The meaning could also depend on some part A of the expression which is not manifest in the meanings of its constituents. In these cases, we will use an operation in A to smuggle out the necessary information so that the expression can access it using a handler. The input type of this operation will be the piece of information that we will need to communicate "upwards". The output type will usually be less important, i.e. the trivial type 1. We can think of operations with the output type 1 as setters or producers. This pattern will be particularly useful for smuggling out non-at-issue content (conventional implicatures and presuppositions).

Examples:

• Conventional implicature.

In Potts' logic of conventional implicatures [108], a parsetree interpretation step traverses the syntactic tree of a sentence and scoops up all the conventional implicatures generated by nominal appositives, non-restrictive relative clauses or other supplements. The truth conditions of the sentence are then a combination of the at-issue proposition and all the conventionally-implicated propositions. We will need an operation to use inside supplements and other conventional implicature triggers for smuggling out the conventional implicatures. The conventional implicatures will be propositions and so the input type will be o. We do not need to communicate anything through the output type and so we will leave it at 1.

implicate : o ↣ 1 • Presuppositions.
Presuppositions form another truth-conditional component of the meaning of a sentence next to at-issue content and conventional implicatures. Them being not at-issue makes them a good candidate for being analyzed using effects. Let us be more specific and look at the presuppositions triggered by definite descriptions. The noun phrase the X presupposes that the set of Xs is not empty (e.g. the noun phrase the king of France presupposes that there is a king of France). Previously, we have introduced an operation find : (ι → o) ↣ ι for dealing with definite descriptions. We now see that this operation doubles as a mechanism with which the definite description can report a presupposition: find! X triggers a presupposition that X is not empty and asks for the contextually salient element of X. If we ignore the output type, we can think of it as a producer of presuppositions of the form ∃x. x ∈ X.

Finally, sometimes we will run into cases for which the getter/setter or consumer/producer intuitions will not apply, as in the case of the scope operator we used in 6.4. In order to derive the type for scope, we have used the second process we use for designing effect signatures, which we will discuss shortly. However, even in the case of scope, we can reason about its type by asking what it gives to the context (the input type) and what it expects from the context (the output type). When we are dealing with a quantified noun phrases, what we have in hand, semantically, is a generalized quantifier. However, we are trying to find an individual as the noun phrase's referent. By juxtaposing what we have, (ι → o) → o, and what we want, ι, we get the type of scope : ((ι → o) → o) ↣ ι. We can see the quantified noun phrase as contributing a quantifier to the context (the nearest sentence will need this quantifier in order to correctly compute its own meaning) and asking in return for the bound variable which is to act as the noun phrase's "referent". The idea that quantified noun phrases can be interpreted by a process that sends the generalized quantifier somewhere else and puts a variable in its place was already established by Cooper's storage [32].

Looking for Inspiration Elsewhere

We now look at the other process we use to find effect signatures: looking for existing theories of effects. This process of finding effect signatures was itself inspired by Shan's paper on monads in natural language semantics [113]. In it, he revisits several semantic analyses and points out that the structures of types and combinators used within correspond to monads. The point behind the paper is that none of these analyses set out to use a monad. Since our computation types form a free monad (see 3.3.7), we can profit from identifying a monad in an existing linguistic analysis and then embedding that monad in our free monad. Other times, we may find a linguistic analysis which uses non-compositional/impure operators to construct the semantics and then base our operations on those operators.

Our most ambitious use of this technique combines both approaches. The types of de Groote's typetheoretic dynamic logic correspond to a monad of state and continuations. At the same time, the construction rules of DRT are based on a small set of effectful operations. In 7.2, we rewrite DRT construction rules into λ computations and then write a handler which interprets such computations as dynamic propositions in de Groote's dynamic logic.

It is through this process that we chose the type for scope. We have seen delimited continuations, namely shift and reset, used to treat quantification [114, 115] and in Chapter 4, we have seen how to implement shift and reset in λ . Hence for the type of scope, we use the type of shift0 developed in 4.6. The variant of scope that we use in Section 8.5 and that can be used in combination with other effects has the same type as the shift0 in 4.6, ((δ → F E (ω)) → F E (ω)) ↣ δ, with δ = ι and ω = o. In the simplified variant used in 6.4, we discard the F E 's and use the simpler type

((ι → o) → o) ↣ ι.
One of the simplest monads, known as the reader monad, occurs very frequently in formal semantics. The reader monad is the monad that maps types α to types γ → α. It is the monad behind intensionalization, deixis and other pieces of context that meanings tend to be parameterized by. The dual to the reader monad is the writer monad which maps types α to types ω × α where ω is some monoid. Writer monads have been used in theories of expressives, which are a kind of conventional implicature, by Giorgolo and Asudeh [51, 48], Kiselyov and Shan [72] and Barker and Bumford [13].

Spotting monads like this is usually not that difficult because there is just a few common monads that tend to be reused and combined a lot. Most of the interesting ones are introduced already in Moggi's original paper [95]. Other sources of inspiration are libraries in Haskell that implement monads. After we have identified the monad, we still have to figure out the operations we will need to introduce in order to represent the monad in our free monad F E . A great source for this is the technique of characterizing monad transformers by the operations that they enable inside a monad [61, 84]. In these papers and in the documentation to the Haskell monad transformer library mtl [3], one can find for every common monad (transformer) the set of operations that it enables on the monad. For example, the reader monad F (α) = γ → α allows computations to ask for a value of type γ with a getter while the writer monad F (α) = ω × α lets computations write values of type ω with a setter. We can then have the same functionality by making sure that we include these operations as either operation symbols in the effect signature or as handlers. This is exactly what we did with deixis in 6.2 and conventional implicature in 6.3: speaker is the operation that lets computations ask for the identity of the speaker, implicate is the operation that lets computations write conventional implicatures (the monoid in this writer monad is the conjunctive monoid on propositions).

Writing Handlers

After having decided on what operations to include in the effect signature, writing the denotations that use these operations is easy. The other challenging part is being able to give a meaningful interpretation to these operations, i.e. to write handlers. A handler is just a catamorphism on computations. To become familiar with what a catamorphism on a structure like this can do and see more examples, we recommend the existing literature on calculi and languages with algebraic effects and handlers, namely [16] and [63].

When (Not) to Use Effects

The motivation for using a calculus of effects such as λ when doing semantics is that we can eliminate a lot of the boring boilerplate which manages:

• passing the current possible world, current speaker and other deictic parameters from expression to subexpression

• threading the discourse state from one denotation to another

• chaining continuations of meanings which might project quantification

• collecting conventional implicatures from supplements

We can use the general notion of chaining computations using ≫= and a lot of these issues work themselves out. This is because the effects automatically project themselves out (unless they are handled) and we can ignore them and focus on the at-issue content. These kinds of projecting behaviours are common in language (as testified by the above list of things we normally have to pass around) and so this technique is quite useful. However, there are cases when existing semantic analyses lift their types to accommodate some new phenomenon, maybe even using a monad, but adapting the analysis to use effects turns out not to be a good idea.

Blom, de Groote, Winter and Zwarts [21] use option types in the abstract language of an ACG to represent optional arguments. The option type N P o is inhabited by NPs and by the value ⋆ (N P o can be written using sums and products as N P + 1). Interpretations of constructions that accept optional arguments are then obliged to specify what interpretation should be used in case the argument is not present. In the syntactic interpretation, a missing argument is often interpreted as an empty string whereas in the semantic interpretation, a missing argument is commonly interpreted by some existential quantification. The system can then assign the meaning ∃x. love j x to the sentence "John loves" (abstract syntax  ⋆ J).

There is an option monad which maps types α to types α o . The side effect that this monad implements is partiality. Computations with this effect can stop and decline to provide a result. This can be expressed with an operation abort : 1 ↣ 0. The impossible output type 0 signifies that this operation cannot be resumed or answered to. In the lexical entries for constructions that accept optional arguments, we use a handler for abort that handles missing arguments by replacing them with the default argument (e.g. an existential quantification).

This solution can be problematic in light of the projecting behavior of effects. If we ever forget to include a handler for abort in e.g. the lexical entry for the verb reads, then we would assign the meaning ∃x. love m x the sentence "Mary loves that John reads". The missing argument to reads would not be handled and project out which would result in loves seeing an argument which uses abort and therefore treating it as a missing argument. This can be easily solved by having distinct abstract types for optional and non-optional NPs and only permit the appearance of abort in the interpretations of optional constituents (i.e. N P = F E (ι) and N P o = F E⊎{abort:1↣0} (ι)). Then, a lexical entry which accepts an optional argument but does not explicitly handle the case when it is missing would not type-check. However, since we end up having to use distinct types for optional and non-optional items and are always forced to explicitly handle the case when an argument is missing, it makes little sense to treat optionality as an effect instead of directly using option types (i.e. having

N P o = N P o = F E (ι) o
). This is a thing to remember: when using λ , we are not obliged to use effects every time it is possible. If it does not lead to a simpler solution, we can use existing techniques side-by-side with effects. We will see another example of a semantic analysis that is based on lifting the types of denotations and that is not suitable for a solution using effects. Sai Qian's implementation [111] of Double Negation DRT [78] extends de Groote's type-theoretic dynamic logic. However, the lifting of the types and the associated terms do not form a functor, and therefore not a monad. Since our computation types form a free monad, embedding a structure which does not fit the laws within them is difficult. We will return to this problem after having covered dynamic semantics, in 7.4.

Dynamic Semantics in λ

We will now examine dynamic semantics. We will consider two theories of dynamics in natural language: Kamp's DRT [64] and de Groote's TTDL [38, 80]. We will build a λ analysis of dynamics and link it to both theories, as a side effect showing how DRT links to TTDL. The analysis we will present can be motivated on the grounds of either DRT or TTDL. We can look at the monad at the core of TTDL and devise operations that let us perform interesting things within the monad (quantifying over the discourse and modifying the discourse state). While this is the process that we have followed to discover this analysis (presented in [89]), we will follow a novel strategy in this exposition. We will start with DRT, more specifically its presentation in Kamp and Reyle's canonical textbook [64], and show how to translate it into λ computations (Section 7.2). We will then interpret those computations as TTDL dynamic propositions.

Afterwards, we will have our first taste of combining different effects. We will enhance our theory of dynamics with a treatment of presuppositions covering projection, cancellation and accommodation. Our analysis will be based on Lebedeva's extension of TTDL [80], which uses exceptions and exception handlers to handle presupposition projection and accommodation. We will see a variation of this approach in terms of effects and handlers (Section 7.3).

Finally, we consider one more extension of TTDL, Qian's double-negation TTDL. This will be an example of a negative result. We will see why and how Qian's DN-TTDL evades an analysis in λ (Section 7.4). 154 Chapter 7. Dynamic Semantics in λ

DRT as a Programming Language

We will argue that the construction rules for DRSs as presented in [64] can be seen as an operational semantics for a programming language. Once we will have established that DRT is a programming language, we will use techniques similar to those in Chapter 4 to embed this language in λ .

DRS-Construction Algorithm

Input:

discourse D = S 1 , . . . , S i , S i+1 , . . . , S n the empty DRS K 0

Keep repeating for i = 1, . . . , n:

(i) add the syntactic analysis [S i ] of (the next) sentence S i to the conditions of K i-1 ; call this DRS K * i . Go to (ii). (ii) Input: a set of reducible conditions of K * i Keep on applying construction principles to each reducible condition of K * i until a DRS K i is obtained that only contains irreducible conditions. Go to (i).

In 5.3.1, we have seen that the conditions of a DRS resemble formulas of predicate logic: predicates applied to variables and logical operators such as negation, implication or disjunction. However, during DRS construction, this notion is expanded. The formulas described above are called irreducible conditions. Along with them, we will also have syntactic trees as conditions. Furthermore, these syntactic trees might contain discourse referents.

We will look at DRS construction for an example from [64] We insert the syntactic analysis of the first sentence into the empty DRS. Then there is a reduction rule which replaces the NP Jones with a discourse referent x while at the same time introducing the discourse referent x and the condition Jones x into the DRS. In the next DRS, we evaluate the object by replacing it with y and adding the discourse referent y and a condition in which (the meaning of) the noun Porsche is applied to y. [64] stops. However, in order to be a little bit more uniform, we will reduce the piece of syntax [x owns y] and replace it with an atomic formula own x y. We can now add the syntactic analysis of the second sentence and proceed with computation.

. . u

Again, we start by evaluating the subject. This time, it is a pronoun, but the process remains largely the same. We replace the pronoun with a new discourse referent u, which we introduce into the DRS along with the condition u = y.

CR.LIN

Triggering configuration γ ∈ Con K : . . . . N(v) . . .

. . α

Replace γ by: α(v)

C ::= [] | x 1 … x n γ 1 … ¬C … γ m | x 1 … x n γ 1 … C ⇒ K … γ m | x 1 … x n γ 1 … K ⇒ C … γ m | x 1 … x n γ 1 … C ∨ K … γ m | x 1 … x n γ 1 … K ∨ C … γ m
The reducible conditions are syntactic trees. The triggering configuration can be found in any part of a syntactic tree and so we define C γ to be a context that places [] inside a syntactic tree. For every rule A → B 1 . . . B n , there will be a production rule for the context C γ ::= A(B 1 , . . . , B i-1 , C γ , B i+1 , . . . , B n ).

C γ ::= [] | S ✟ ✟ ❍ ❍ C γ VP | S ✟ ✟ ❍ ❍ NP C γ | VP ✟ ✟ ❍ ❍ C γ NP | VP ✟ ✟❍ ❍ V C γ | . . .
The construction rule CR.ID is then a reduction rule on these forms:

C                     x 1 … x n γ 1 … C γ         S ✟ ✟ ❍ ❍ NP ✟ ✟ ❍ ❍ DET a(n) N VP ′         … γ m                     → CR.ID C               x 1 … x n u γ 1 … [N](u) C γ [ S ✟ ✟ ❍ ❍ u VP ′ ] … γ m              
Likewise, there is an analogue for evaluating indefinite descriptions in object positions which differs only in the triggering configuration. The reduction rules for CR.PRO, CR.LIN and CR.LITV can be derived in the same way. Then, the DRS that corresponds to a sentence can be seen as a normal form 125 in this reduction system.

If we look at the rule, then we can see a remarkable similarity to the rules seen in Chapter 4 for λ shift and λ shift0 . Inside the context C, we have some kind of delimiting construction, a DRS in one case and [START_REF] William | Intensional interpretations of functionals of finite type i[END_REF] The system permits reductions in different conditions at the same time and is therefore not confluent.

λ Analysis

159 a reset in the other. As one of the arguments of this construction, we have an expression buried inside a more limited context, C γ , which cannot contain any more nested DRSs, and F , which cannot contain any more resets. In the case of DRT, this buried expression is an indefinite or a pronoun which wants to access the context's DRS to add (and possibly look for) discourse referents and conditions. In the case of λ shift , the buried expression is a shift that wants complete control over the context inside the reset. In our analysis of λ shift , reset corresponded directly to a handler. Therefore, we will be treating DRSs as handlers in the coming λ analysis. The denotations of indefinites and pronouns will use operations to introduce new discourse referents and conditions and to query the state of discourse to resolve anaphora.

λ Analysis

The first step in building a λ analysis of dynamics is to design the effect signature: how many operations we will need, what their types should be and what they should do. However, our task is largely facilitated by the fact that in their exposition of DRT [64], Kamp and Reyle have structured the construction rules by using a limited set of operations to manipulate the DRSs. It is these operations that we will include in our effect signature. Consider the construction rule for pronouns and the corresponding representation as a λ computation.

CR.PRO

Triggering configuration

γ ⊆ γ ∈ Con K : . . . . S. . . . . . . VP ′ . . . . . NP . . . . . PRO . . . . . α                            or: . . . . VP . . . . . . . NP . . . . . PRO . . . . . α . . . . . V                            Choose suitable antecedent v, such that v is
α = choose ⋆ (λv. introduce ⋆ (λu. assert (u = v) (λ_. η u)))
Let α be a third-person singular pronoun. [START_REF] Tarski | A lattice-theoretical fixpoint theorem and its applications[END_REF] The construction rule reduces the NP node formed by α into a discourse referent. In the corresponding analysis in our formalism (ACG + λ ), we have α as an abstract constant of type N P whose semantic interpretation is a computation of type F E (ι). The pronoun asks the context for a suitable antecedent, which is then referred to as v. We mimic the verb choose with an operation choose. It does not take any input, as no input is given to choose in the construction rule, [START_REF] Tarski | Arithmetical extensions of relational systems[END_REF] and expects a discourse referent as output. Since we will be using the type ι for terms that designate individuals, we will identify the type of discourse referents with ι. Next up, the construction rule demands the introduction of a new discourse referent into the DRS K that contains the condition being evaluated. This instruction and its use of the verb introduce gives rise to the introduce operation. introduce asks for a fresh discourse referent and so its type ends being the same as the one for choose, only the semantics differ.

introduce : 1 ↣ ι The next step in the construction rule asks the DRS K to introduce a new condition. For this kind of interaction, introducing a condition, we will use a new operation, assert. The NP indicates the condition it wants to add to the DRS, the truth condition that it wants to assert. Conditions are atomic formulas of predicate logic and so we will use o, the type of propositions, to represent them. The output will be of the trivial type 1.

assert : o ↣ 1
Finally, the construction rule tells us to replace the NP node with the discourse referent u. This means that when this NP occurs as an argument to a predicate, the predicate should be applied to the discourse referent u. In λ , this role is played by the return values of computations (see equation below). Therefore, we return u with the computation η u.

predicate •≫ (op M p (λx. . . . η u)) = op M p (λx. . . . η (predicate u))
We can do the same kind of analysis/translation for the CR.ID rule for indefinite descriptions.

. . V

                           Introduce in U K : new discourse referent u Introduce in Con K : new condition [N ](u) Substitute in γ: u for . . . . NP . . . . . . . N . . . . . DET . . . . . a(n)  : N -• N P N = F E (ι → o) N P = F E (ι)  = λN. introduce ⋆ (λu. N ≫= (λn. assert (n u) (λ_. η u)))
The CR.ID rule evaluates a noun phrase which is composed of the indefinite article followed by some noun N . This construction is represented in our ACG as an abstract constant  : N -• N P . Its denotation will be a function from N to N P . As in the rest of the analyses seen in this chapter, we will take N = F E (ι → o), which meshes with the fact that DRT expects nouns to reduce to predicates.

The evaluation of the noun phrase "a N " starts by introducing a fresh discourse referent u and so we use the same operation as in CR.PRO. Then we will proceed by adding the condition [N ](u). Note that in the DRT rule, we are dealing with a reducible condition ([N ] is the syntax of N ). In adding this reducible condition, DRT essentially schedules the evaluation of the syntactic expression [N ] via some other construction rule (CR.LIN if N is only a common noun, other rules if it is, e.g., restricted by a relative clause or an adjective). In λ , we achieve a similar effect by asking for the evaluation of N using 7.2. λ Analysis 161 the ≫= operator. We then state that once the noun has been evaluated down to a predicate, we want this predicate, applied to the referent u, to be a condition inside the DRS. Finally, as in CR.PRO, we present the discourse referent u as the referent of the noun phrase.

For completeness, we will also give translations for the CR.LIN and CR.LITV rules, even though they do not have any dynamic effects of their own.

CR.LIN

Triggering configuration

γ ∈ Con K : . . . . N(v) . . .

. . α

Replace γ by: α(v)

 : CN -• N CN = ι → o N = F E (ι → o)  = λα. η (λv. α v) = λα. η α = η
We assume that behind every common noun α lies a set of individuals, a predicate α. The lexical insertion rule for nouns replaces the noun by that predicate. We can capture the same line of reasoning in ACGs. We contrast the category CN of common nouns (such as snowman, snake, ladder) to the larger category N of nouns (animal in your garden, man who owns a donkey). The common nouns will correspond to plain sets of individuals, CN = ι → o. However, more complex nouns might also have effects [START_REF] Unger | Dynamic semantics as monadic computation[END_REF] and so we have N = F E (ι → o). In ACGs, to say that every common noun CN is a noun N is to provide an injection of type CN -•N . Homomorphically, its denotation will be an injection from ι → o to F E (ι → o), the constructor η.

CR.LITV

Triggering

. . x

Replace γ by: α(x, y)

 : V -• N P -• N P -• S V = ι → ι → o N P = F E (ι) S = F E (o)  = λαY X. X ≫= (λx. Y ≫= (λy. η (α x y))) = λαY X. α •≫ X ≪•≫ Y
With CR.LITV, the idea behind the DRT/ λ analogy is the same as with CR.LIN. Behind every (extensional transitive) verb α lies a binary relation, also called α. When combined with a subject and an object, verbs form sentences. This is embodied by the ACG abstract constant  which maps verbs from V into functions in N P -• N P -• S. From the triggering configuration of the rule CR.LITV, we see that (the parent of) the subject dominates (the parent of) the object. This leads DRT to always evaluate the dynamic effects of the subject before the object. In λ , this feature is expressed in the lexical entry for the construction that combines the subject, verb and object into a sentence, , where X is evaluated before Y using ≫=.

Example

We have seen how to map the syntax-semantics construction rules of DRT into the ACG formalism and how the extra steps performed when reducing indefinites or pronouns in DRT correspond to operations, with which we have extended ACG's λ-calculus in λ . We can now look at an example in action. (19) A man owns a Porsche. It fascinates him. This is a small variation of Example 6 in which Jones was replaced by a man. [START_REF] Unger | Dynamic semantics as monadic computation[END_REF]   ( ( P)) ( ( ))

↠ introduce ⋆ (λx.
assert (man x) (λ_. introduce ⋆ (λy.

assert (Porsche y) (λ_.

η (own x y)))))
The only effects are due to the indefinites that introduce new discourse referents and assert truth conditions. The operations are ordered subject-first, object-last and the computation returns the predicate that is the application of the verb's predicate to the referents of the subject and the object. The same goes for the second sentence in Example 19:

    ↠ choose ⋆ (λy ′ .
introduce ⋆ (λu. assert (u = y ′ ) (λ_.

choose ⋆ (λx ′ . introduce ⋆ (λv.

assert (v = x ′ ) (λ_. η (fascinate u v)))))))
We can compose the two using ≪∧≫, the conjunction of propositions raised to computations.

  ( ( P)) ( ( )) ≪∧≫     ↠ introduce ⋆ (λx. assert (man x) (λ_. introduce ⋆ (λy. assert (Porsche y) (λ_. choose ⋆ (λy ′ . introduce ⋆ (λu. assert (u = y ′ ) (λ_. choose ⋆ (λx ′ . introduce ⋆ (λv. assert (v = x ′ ) (λ_. η (own x y ∧ fascinate u v))))))))))
) [START_REF] Unger | Dynamic semantics as monadic computation[END_REF] We relegate the discussion of proper nouns to Section 7.3.

λ

¬ TTDL : Ω → Ω ¬ TTDL A = λeϕ. ¬(A e (λe. ⊤)) ∧ ϕ e
We know that λeϕ. M ∧ϕ e corresponds to η M and that A e (λe. ⊤) is box A e. Therefore, we can define our dynamic negation by:

¬ _ : F E (o) → F E (o) ¬ A = η (¬(box A e))
However, there is a small catch. We have a free variable e of type γ. This is supposed to be the context in which the new negated condition is to appear. This is necessary so that the anaphoric elements within the negated condition can refer to not only the referents proper to the negated DRS, but also to those originating in superordinate DRSs. We can introduce a new operation for accessing the context. get : 1 ↣ γ Now, we can have dynamic negation as:

¬ A = get ⋆ (λe. η (¬(box A e)))
We can see the analogy with CR.NEG: the negation of A puts A inside a box, the box is then negated and returned as the new condition. The name box for this kind of handler was motivated exactly by this kind of analogy, wherein a handler is used to contain dynamic effects inside some scope.

We have introduced a new operation into our dynamic effect signature. This means that we will have to extend our handlers to cover the new operation. However, before we do so, we note that choose can be expressed in terms of get and sel:

choose = λ_k. get ⋆ (λe. k (sel e))
Therefore, we will drop choose and keep only get. We have now arrived at our final effect signature for DRT dynamics. This signature allows us to treat dynamic effects the same way as the other effects that we have analyzed in Chapter 6.

E DRT = { get : 1 ↣ γ, introduce : 1 ↣ ι, assert : o ↣ 1 } get ⋆ (λe. get ⋆ (λe ′ . M (e, e ′ ))) = get ⋆ (λe. M (e, e)) M = get ⋆ (λe. M )
As with the speaker getter from 6.2, we get two laws telling us that asking for the context is idempotent (first equation) and that it has no other bearing on the result of the computation (second equation).

Since we know how assert and introduce modify the context, we can reorder get w.r.t. these two operations:

assert A (λu. get ⋆ (λe. M (u, e))) = get ⋆ (λe. assert A (λu. M (u, A :: e))) introduce ⋆ (λx. get ⋆ (λe. M (x, e))) = get ⋆ (λe. introduce ⋆ (λx. M (x, x :: e)))
This means we can assume that every computation of type F E DRT (1) uses get exactly once and does so at the very beginning, i.e. it is of the form get ⋆ (λe. M (e)) where M (e) : F {implicate,assert} (1). [START_REF] Wadler | The essence of functional programming[END_REF] If we assume that the relative order of discourse referents and conditions is not important (e.g. they are both separate parts, as in a DRS), or in other words we have that (x :: p :: e) = (p :: x :: e) for every x : ι, p : o and e : γ, then we get the following equation:

assert A (λu. introduce ⋆ (λx. M (u, x))) = introduce ⋆ (λx. assert A (λu. M (u, x)))
This will allows us to move introduce operations above assert operations so that we can have the following canonical representation for computations of type F E DRT (1):

get ⋆ (λe. introduce ⋆ (λx 1 . . . . introduce ⋆ (λx n . assert c 1 (λ_. . . . assert c m (λ_. η ⋆)))))
In other words, the computation examines its context e and then produces the DRS:

x 1 … x n c 1 . . . c m
Note that as in TTDL, discourse referents correspond to λ-binders in λ and their standard notion of α-equivalence gives rise to α-equivalence for our representations.

If we were to further assume that the order in contexts does not matter at all (e.g. the discourse referents and conditions form sets, as in a DRS), meaning that we have (x :: y :: e) = (y :: x :: e) and (p :: q :: e) = (q :: p :: e) for every x, y : ι, p, q : o and e : γ, then we get the following:

assert A (λu 1 . assert B (λu 2 . M (u 1 , u 2 ))) = assert B (λu 2 . assert A (λu 1 . M (u 1 , u 2 ))) introduce ⋆ (λx. introduce ⋆ (λy. M (x, y))) = introduce ⋆ (λy. introduce ⋆ (λx. M (x, y)))
Since the discourse referents and conditions are (unordered) sets in the presentation in [64], this would make our representation closer to DRSs.

Furthermore, if we assume that the conditions in a context can be seen as a big conjunction, i.e. (p ::

q :: e) = ((p ∧ q) :: e) for every p, q : o and e : γ, then we admit the following equations:

assert A (λu. assert B (λu ′ . M (u, u ′ ))) = assert (A ∧ B) (λu. M (u, u))
which gives us a simpler canonical representation:

get ⋆ (λe. introduce ⋆ (λx 1 . . . . introduce ⋆ (λx n . assert p (λ_. η ⋆))))
This boils down a computation of type F E DRT (1) into a proposition p that depends on some context e and introduces the new discourse referents x 1 , …, x n .

Finally, we will look at the particular case of the computation that serves as the denotation of an anaphoric pronoun: The first equation, which exchanges y with sel e, is licensed by the fact that the box handler will interpret the first computation as the proposition ∃y. sel e = y ∧ k y and the second computation as the proposition ∃y. sel e = y ∧ k (sel e), both of which are equivalent.

The simplification in the second equation is based on an assumption that ((sel e = y) :: y :: e) = e. In other words, if an individual is already present in the context (the individual sel e), adding them again under a different name (y) does not change the context. While certain strategies of anaphora resolution might rely on individuals being repeatedly added to the context on every use, [START_REF] Wu | Transformers, handlers in disguise[END_REF] we allow ourselves this modification to simplify the derivations in the coming examples and make the resulting logical formulas more readable. Therefore, we will be using this simplified denotation for anaphoric pronouns:

 = get ⋆ (λe. η (sel e))

Presuppositions

In our λ analysis of anaphora, we have completely omitted proper nouns, even though they are treated by DRT in [64] and feature in Example 6. This is due to the fact that proper nouns trigger presuppositions: . . Jones sleeps presupposes that there is some (contextually salient) entity named Jones. These presuppositions project outside of entailment-cancelling operators such as negation, outside of the DRSs in which they are contained.

. . α                            or: . . . . VP . . . . . . . NP . . . . . PN . . . . . α . . . . . V                            Introduce into
(20) It is not the case that Jones 1 owns a Porsche. He 1 owns a Mercedes.

In Example 20, the proper noun Jones contributes a discourse referent which is then picked up in the second sentence. This would be impossible to achieve using introduce, since that would contribute the referent only to the DRS (box) that is being negated and the discourse referent would not reach the second sentence.

If we look at the construction rule for proper nouns in DRT, CR.PN, displayed on Figure 7.5, we will see that the discourse referent and the condition describing it are being inserted into the main DRS and not into the DRS K in which the condition being reduced appears.

In TTDL, this issue was resolved by adding exceptions into the lambda calculus used for the semantic terms [80]. The lexical entry for a presupposition trigger such as a proper noun or a definite description throws the exception AbsentIndividualExc P . This exception carries the predicate P that describes the entity that is presupposed to exist. At the top level, a handler catches these exceptions and accommodates these presuppositions. We have seen that in λ , dynamic propositions are modelled as computations and these computations already have a notion of throwing exceptions (effects) and handling them (handlers). We will introduce an operation named presuppose. Its input type will be ι → o, a predicate that describes the entity whose existence is presupposed. The output type will be ι, the presupposed entity satisfying the predicate.

presuppose : (ι → o) ↣ ι
The type of this operation is not exactly equivalent to the exception AbsentIndividualExc from [80]. As we have seen in Chapter 2.2.3, exceptions are effects that have the impossible output type 0, which means that no handler will be able to resume the computation by using the continuation. In Lebedeva's approach, when the toplevel handler intercepts the exception, it accommodates the presuppo-sition, rewinds the dynamic state and evaluates the sentence again, this time with a context which now contains the presupposed entity. This is not suitable to our approach because of two reasons:

• We will deal with many other effects besides dynamic state and rewinding all of their effects in order to evaluate the sentence again in a new context would be needlessly complex.

• This approach over-generates by licencing the reading "He 1 loves John's 1 car". When evaluating John, the existence of John is presupposed and the sentence is evaluated again, this time in a context in which John is accessible. However, this will allow the pronoun in subject position to resolve to John and end up being bound by the object.

The effects in λ differ from traditional exceptions in that they are resumable. Besides having the input type (which is the message type of a traditional exception), they also have an output type. Handlers can then resume computation at the point of the effect by calling the continuation with a value of the output type. We make full use of this in our treatment of presuppositions by using ι as the output type of presuppose. This way, we do not have to abort the evaluation of the sentence, rewind all of the effects and evaluate it again; we return the presupposed entity immediately and the evaluation of the sentence continues. This strategy also avoids the over-generation mentioned above, in which a presupposition trigger binds a pronoun preceding it.

We have shown how the presuppose operation can be motivated on the grounds of the analysis done by Lebedeva in [80]. We can also look at how it ties to the DRT construction rule for presupposition triggers such as CR.PN. When translating construction rules into computations, we have implemented the Introduce in U K command as the introduce operation and the Introduce in Con K command as the assert operation. We might therefore proceed the same way and translate the Introduce into the universe of the main DRS command as some operation introduce_main : ⋆ ↣ ι and Introduce into the condition set of the main DRS command as assert_main : o ↣ 1. However, by looking at the construction rules of presupposition triggers, we see that they tend to use the two operations in tandem: first introduce a new discourse referent and then some condition(s) describing it. Therefore, we can fuse the two into a single operation presuppose : (ι → o) ↣ ι, which introduces and outputs a new discourse referent x while at the same it introduces the condition P x, where P is its argument.

Besides lowering the number of basic operations that we have to introduce, this also has an advantage when we start to consider ambiguous ways of accommodating presuppositions (7.3.4). Suppose we have two operations, introduce_somewhere and assert_somewhere, that let us introduce discourse referents and conditions into arbitrary DRSs on the projection line. 135 We might then end up accommodating the discourse referent and the condition in different DRS, yielding an undesired meaning. If we package the two operations into a single presuppose_somewhere, then we do not have this problem.

Revising the Dynamic Handler

We will want to introduce the presuppose operation into our dynamic semantics in such a way that presuppose projects outside of boxes (DRSs, applications of the box handler). This means that applying the box handler to a computation should yield a computation free of get, introduce and assert but still possibly using presuppose: box will be an open handler for get, introduce and assert. The open handler will be more complex, since where before we had continuations which returned simple propositions, or rather functions from contexts to propositions, we will now have continuations which return computations.

• The cost of replacing the simpler closed handler with the open handler is a price we would have to pay anyway if we wanted to use this handler in a setting that involved other effects (such as quantification, deixis, conventional implicature); it is not limited to adding support for presuppositions. E.g., in Chapter 8, we will deal almost exclusively with open handlers.

• The box handlers are by far the largest handlers in our analyses. Furthermore, open handlers that thread some mutable state throughout the computation are slightly awkward to write (as testified by all the uses of ≪•) in pure languages without using some syntactic sugar, such as parameterized handlers that can automatically thread some parameter from operation to operation as in [63, 70].

The open box handler outputs computations of propositions instead of simple propositions, which is something we have to take into account when using it in, e.g., negation:

¬ A = get ⋆ (λe. box A e ≫= (λa. assert! (¬a)))
Now that we have an open version of the box handler, there is one change that we will make in how it actually functions. We will motivate it by the following example.

(21) It is not the case that John 1 likes his 1 car.

The negation will use get to retrieve the current context e and then proceed by evaluating the expression (box John likes his car e). The proper noun John will then use presuppose, which will project out of the box and introduce John into the global context. But now we have to evaluate the pronoun his in the context e which was untouched by John and we will thus fail to retrieve John and get the expected reading. The problem is in our definition of ¬ A. We want anaphoric expressions within A to have access to referents introduced outside of A. We do this by using get to recover the context e in which we are about to evaluate ¬ A and then use that context as the initial context when interpreting anaphora in A with box A e. While this works well for TTDL, in which dynamic propositions have no way to modify contexts other than the local one, it breaks when we let presuppose modify the top context.

The solution is to dismiss the assumption that surrounding contexts are immutable. Whenever we handle a get, we use another get to gather the current state of the surrounding (global) context and then combine that with the local context. This solution will actually simplify the definition of ¬ and the type of box, since box does not need to be seeded with its surrounding context but retrieves it itself when necessary. Furthermore, note that this solution was not available to us before we made the handler open, since it interprets computations of type F E DRT (1) as computations of type F {get} (o).

box :

F E⊎E DRT (1) → F E⊎{get} (o) box = λA. ( get: (λ_k. η (λe. get ⋆ (λe ′ . k (e + + e ′ ) ≪• e))), introduce: (λ_k. η (λe. ∃ ≫ x. k x ≪• (x :: e))), assert: (λpk. η (λe. p ∧≫ (k ⋆ ≪•(p :: e)))), η: (λ_. η (λe. ⊤)) A) ≪• nil
The get now uses another get to retrieve the current surrounding context e ′ , which is then combined with the local context e as the answer to the original get. In order to combine the two contexts, we assume that there is some operation (+ +) : γ → γ → γ. If contexts are (pairs of) lists, then this operation would be (pointwise) list concatenation. Since we always ask again for the surrounding context, we do not need the surrounding context as an argument to box. Instead, we pass in nil as the initial local context, where nil : γ is a constant representing the empty context, e.g. an empty list.

As we no longer need to supply the initial surrounding context, dynamic negation becomes simpler:

¬ A = box A ≫= (λa. assert! (¬a))

Presupposition in Action

With presuppose in place, we can now translate the DRT construction rule for proper nouns, CR.PN, into λ :

CR.PN Triggering configuration γ ⊆ γ ∈ Con K : . . . . S. . . . . . . VP ′ . . . . . NP . . . . . PN . . . . . α                            or: . . . . VP . . . . . . . NP . . . . . PN . . . . . α . . . . . V                            Introduce into
 = λα. presuppose (λu. α u) (λu. η u)
We model the introduction of a discourse referent and a condition into the main DRS with the presuppose operation. As with the lexical insertion rules for common nouns and transitive verbs, this rule is parameterized by a lexical item, this time a proper noun. In DRT, proper nouns are described using predicates and so we introduce an abstract atomic type P N for proper nouns whose interpretation P N is the type of predicates. The definition of  above is expanded in order to parallel the construction. We can actually make it a lot shorter:

 = λα. presuppose (λu. α u) (λu. η u) → η λα. presuppose α (λu. η u) = λα. presuppose! α → η presuppose!
We will also need a handler to give a meaning to the presuppose operation. The meaning behind presuppose is clear: it will introduce a discourse referent and a condition.

accommodate : F E⊎{presuppose} (α) → F E (α) accommodate = presuppose: (λP k. introduce ⋆ (λx. assert (P x) (λ_. k x)))
The accommodate handler turns presupposed content into asserted content. The place we want to do that is usually on the level of the topmost DRS. We can define a combinator which corresponds to the idea of a top DRS.

top : F E⊎E DRT ⊎{presuppose} (1) → F E⊎{get} (o) top = box • accommodate
We can now deal with Example 20. We start by computing the denotation of the first sentence.

S 1 =   ( ( P)) ( J) ↠ presuppose Jones (λx.
introduce ⋆ (λy.

assert (Porsche y) (λ_. assert (own x y) (λ_.

η ⋆))))
Wrapping a dynamic negation over this will resolve all the introduce and assert operations, but the presuppose will prevail.

¬ S 1 ↠ box S 1 ≫= (λa. assert! (¬a)) ↠ presuppose Jones (λx.
η (∃y. Porsche y ∧ own x y)) ≫= (λa. assert! (¬a))

↠ presuppose Jones (λx. assert (¬(∃y. Porsche y ∧ own x y)) (λ_.

η ⋆))

We now turn to the second sentence in Example 20, whose meaning is derived below. assert (own (sel e) y) (λ_.

η ⋆))))))

We can now embed this in the top-level box. where e ′ = ¬(∃y. Porsche y ∧ own x y) :: Jones x :: x :: e By assuming that x is the salient antecedent for the pronoun or by evaluating in the empty context nil, we get the intended reading.

empty : F E⊎{get} (α) → F E (α) empty = get: (λ_k. k nil) empty (top not S 1 . S 2 )
↠ η (∃x. Jones x ∧ ¬(∃y. Porsche y ∧ own x y) ∧ (∃y. Mercedes y ∧ own x y))

Cancelling Presuppositions

It has been observed that not every presupposition projects. A presupposition can be blocked or cancelled in certain contexts. The sentence "John's car is cheap" presupposes that there is someone named John who owns a car. However, if we put this sentence into a conditional context, as in Example 22, the presupposition that John owns a car disappears. (22) If John owns a car, then his car is cheap.

Lebedeva [80] solves this in TTDL by making the presupposition triggers first search the context for their referent. If the necessary referent is present in an accessible context, then it is retrieved and no presupposition is triggered. We can do the same in our setting. Let sel P : (ι → o) → γ → (ι + 1) be a function that retrieves from a context of type γ the salient individual that satisfies the predicate of type ι → o, if such an individual exists in the context. Otherwise, it returns inr ⋆. find : (ι → o) → F E⊎{get,presuppose} (ι) find = λP. get ⋆ (λe. case sel P P e of {inl x → η x; inr _ → presuppose! P }) find examines its context and searches it for an individual satisfying the predicate. If no such individual is found, it triggers a presupposition. The type of find is (almost136 ) the same as that of presuppose! and so we can replace all uses of presuppose! with find to get the correct behavior w.r.t. cancelling of presuppositions.

 : P N -• N P  = find  : N P -• N -• N P  = λXN. X ≫= (λx. N ≫= (λn. find (λy. n y ∧ own x y)))
The possessive construction X's N uses find to behave either as a bound pronoun, using sel P to retrieve its referent from the context, or if there is no suitable referent, as a presupposition trigger.

The final part of the puzzle is how to make the context of the antecedent (John owns a car) available in the consequent (his car is cheap). DRT has special accessibility rules for implications, but in Subsection 5.3.4, we have seen how to translate DRT implications into negations and conjunctions while preserving accessibility. 137 We will use the same strategy to correctly deal with accessibility in conditional utterances.

-

: S -• S -• S - = λAB. A → B = λAB. ¬(A ∧ ¬ B) = λAB. ¬(A ≫= (λ_. ¬ B))
The dynamic implication used in - explains how conditionals can filter presuppositions. A new box is opened using the outer negation. Into that box, A will introduce new discourse referents and truth conditions. These will then be able available to B, which might resolve some of B's presuppositions. Since the whole conditional is inside a box due to the dynamic negation, the filtering effect will subside after the consequent, i.e. dynamic implication is externally static [53].

In Example 22, the sentence in the antecedent introduces into the context John (x, John x), a car (y, car y) and the fact that John owns the car (own x y). The sentence in the consequent then has access to this context and can resolve his to x and then retrieve y using sel P , thus preventing the triggering of a presupposition.

Instead of using find in the lexical entry of every presupposition trigger, there is also an alternative implementation that is more in the spirit of λ . We can change the semantics of presuppose from "introduce a new top-level discourse referent satisfying the predicate" to "find a salient individual satisfying the predicate". If the context can satisfy the presuppose operation by binding the presupposition trigger to an existing discourse referent, it might choose to do so. This way, all presupposition triggers consistently use presuppose. The cancelling then happens at the level of a box (a DRS) which might decide to satisfy the presupposition by supplying an existing discourse referent.

useFind : F E⊎{presuppose} (α) → F E⊎{get,presuppose} (α) useFind = presuppose: (λP k. find P ≫= k) box : F E⊎E DRT ⊎{presuppose} (1) → F E⊎{get,presuppose} (o) box = box • useFind
We define a handler for presuppose called useFind that tries to cancel the presupposition by looking into the current context for a possible referent. In case there is no such referent, the presupposition is projected onwards. Since useFind can be defined on its own, we can define the new box that cancels presuppositions, box, by composing the old box with useFind. 138 The useFind handler, which is included in box, handles some uses of presuppose and projects others. This captures the reality that some contexts cancel some presuppositions. If we use the box handler, we can now use presuppose in the lexical entries

¬ S 2 = box S 2 ≫= (λa. assert! (¬a)) ↠ get ⋆ (λe.
(case sel P (λz. car z ∧ own (sel e) z) e of {inl z → η z; inr _ → presuppose! (λz. car z ∧ own (sel e) z)}) ≫= (λz.

assert (¬(cheap z)) λ_.

η ⋆))

We now move up to the antecedent S 1 : John owns a car.

S 1 =   ( ( )) ( J)
↠ presuppose John (λx. introduce ⋆ (λy. assert (car y) (λ_.

assert (own x y) (λ_.

η ⋆))))

We can now compute the conjunction of S 1 and ¬ S 2 and observe how the context of S 1 cancels the presupposition in ¬ S 2 .

S 1 ∧ ¬ S 2 = S 1 ≫= (λ_. ¬ S 2 ) ↠ presuppose John (λx.
introduce ⋆ (λy.

assert (car y) (λ_. assert (own x y) (λ_.

get ⋆ (λe.

(case sel P (λz. car z ∧ own (sel e) z) e of {inl z → η z; inr _ → presuppose! (λz. car z ∧ own (sel e) z)}) ≫= (λz.

assert (¬(cheap z)) λ_. η ⋆))))))
≈ presuppose John (λx. get ⋆ (λe. introduce ⋆ (λy.

assert (car y) (λ_. assert (own x y) (λ_.

(case sel P (λz. car z ∧ own (sel e ′ ) z) e ′ of {inl z → η z; inr _ → presuppose! (λz. car z ∧ own(sel(e ′ ), z))}) ≫= (λz.

assert (¬(cheap z)) λ_. η ⋆))))))
where e ′ = own x y :: car y :: y :: e

We compose the two dynamic propositions by concatenating their effects. We then make use of our equations from 7.2.5 to move get above the introduce and assert to make it clear that the context e ′ that is given as argument to sel and sel P contains the necessary material. We do not move get above presuppose since we cannot predict how presuppose will modify the context: if the presupposition gets cancelled and bound by an existing discourse referent, it does not modify the context, but if it is novel and gets accommodated, then it introduces a new discourse referent into the context. However, in all cases we can assume that after performing presuppose P , the context for the subsequent dynamic operations will contain some referent x satisfying the predicate P . Assuming that the context e, and therefore by extension e ′ , contains the discourse referent x and the condition John x, sel e ′ can choose the x as the antecedent for his. We can now compute the denotation of the noun phrase his car in this context and see that the presupposition is cancelled.

case sel P (λz. car z ∧ own (sel e ′ ) z) e ′ of {inl z → η z; inr _ → presuppose! (λz. car z ∧ own (sel e ′ ) z)} = case sel P (λz. car z ∧ own x z) e ′ of {inl z → η z; inr _ → presuppose! (λz. car z ∧ own x z)} = case inl y of {inl z → η z; inr _ → presuppose! (λz. car z ∧ own x z)} → β.+1 η y
We can plug this result back into the computation for S 1 ∧ ¬ S 2 :

S 1 ∧ ¬ S 2
↠ presuppose John (λx. get ⋆ (λe. introduce ⋆ (λy.

assert (car y) (λ_. assert (own x y) (λ_.

η y ≫= (λz. assert (¬(cheap z)) λ_. η ⋆))))))
→ η.≫= presuppose John (λx. introduce ⋆ (λy. assert (car y) (λ_. assert (own x y) (λ_.

assert (¬(cheap(y))) λ_. η ⋆))))
We use the → η.≫= that we derived in Proposition 3.1.4 and we also drop the get since we no longer use the context e (an equation from 7.2.5 admissible under our handlers). The denotation of Example 22 is then the dynamic negation of this computation.

Presuppositions

181 - S 1 S 2 = S 1 → S 2 = ¬( S 1 ∧ ¬ S 2 )
↠ get ⋆ (λe.

(case sel P John e of {inl x → η x; inr _ → presuppose! John}) ≫= (λx.

assert (¬(∃y. car y ∧ own x y ∧ ¬(cheap(y)))) (λ_.

η ⋆)))

Note that the resulting denotation is still accessing the context to determine whether it will presuppose the existence of John or whether it will retrieve John from some (potentially hypothetical) context. This means our solution is compositional and if we were to place this denotation inside the following context, the presupposition of there being some salient John would be cancelled: (23) If there is a poor man called John, then if John owns a car, his car is cheap.

If we consider the sentence of Example 22 in an empty, "out of the blue" context, into which John will need to be accommodated, we get the intended reading.

empty (top - S 1 S 2 ) ↠ η (∃x. John x ∧ ¬(∃y. car y ∧ own x y ∧ ¬(cheap(y)))) = η (∃x. John x ∧ (∀y. (car y ∧ own x y) → cheap(y)))

Ambiguous Accommodation

Presuppositions do not always have to accommodate at the top level. Consider the following example from [17].

(24) (c 0 ) Maybe (c 1 ) Wilma thinks that (c 2 ) her husband is having an affair.

The NP her husband presupposes that Wilma is married. If the sentence is uttered in a context in which it was not yet established that Wilma is married, the fact will need to be accomodated somewhere. We can do so in the global context c 0 , which would mean interpreting the sentence as "Wilma is married and maybe she thinks that her husband is having an affair". However, we can also accommodate the presupposition in the intermediate context c 1 to get the interpretation "Maybe Wilma is married and she thinks that her husband is having an affair". Finally, we can even accommodate the presupposition in the local context c 2 to get "Maybe Wilma thinks that she is married and her husband is having an affair".

If we look at the different possible accommodation sites in Example 24, we remark that they are all lexically generated. There is the possible context/accommodation site c 1 in the argument of the modal operator maybe and there is c 2 in the argument of the attitude verb think. At these points, we would like to be able to interrupt presuppositions and accommodate them. In λ , this would mean applying a presuppose handler to these arguments. However, at the same time, we want to also have the reading in which the presupposition projects out. In 6.4.1, we dealt with ambiguity by changing the syntax, moving quantifiers into their scope using QR. This would not be suitable for presuppositions since they can be accommodated in positions which do not correspond to sentences (e.g. the restrictor of a quantified noun phrase). This time, instead of having a different abstract term for every possible reading, we will make it so that a single object term (i.e. denotation) will represent multiple readings, as when using underspecified representations. Our denotations are computations and we want the denotations to evaluate to multiple different values. This is a feature of nondeterministic computations and we can implement nondeterminism using effects. it in the restrictor of that quantifier (which is accessible, i.e. on the projection line, from the nucleus), giving us "Most Germans who have a car wash it on Saturday". However, we cannot get the global accommodation reading. The problem is that the referent of their is a variable being quantified over by the quantifier most Germans. If this variable is x, then the presupposition being triggered is the existence of an individual satisfying λy. car y ∧ own x y. This predicate contains a free variable x, which means that for every different value x, we actually have a different predicate that identifies a different car. The solution to this binding problem in theories that implement accommodation, such as van der Sandt's DRT approach [130] or Lebedeva's extension of TTDL [80], is to reflect this logical impossibility into a linguistic constraint. Presupposed material cannot project out of a binder that binds some part of that material.

We will look at how a similar example turns out in our system.

(26) (c 0 ) If (c 1 ) a man gets angry, (c 2 ) his children get frightened.

Example 26, taken from [130], is similar in nature to Example 25. We have a presupposition trigger which can be accommodated in a local context (c 2 ) and in an intermediate context (c 1 ), but not in the global context (c 0 ), because of a bound variable. Furthermore, Example 26 is built out of constructions we have already covered and so we are ready to compute the denotation. We do not analyze the construction X's children as a possessive ( X ), which would refer to some children owned by X. Since children is a relational noun, we assume a binary relation children y x expressing that y are children of x.

We then analyze X's children as  X where the semantics of  makes use of the relation children. For the construction X gets A, where A is an adjective, we introduce the abstract constant .  : N P -• N P  = λX. X ≫= (λx. presuppose! (λy. children y x))

 :

ADJ -• N P -• S ADJ = ι → o  = λaX. X ≫= (λx. assert! (a x))
We can now compute the denotation of Example 26. The structure of Example 26 is - S 1 S 2 where S 1 and S 2 are the antecedent and consequent, respectively. Its semantics, - S 1 S 2 , is S 1 → S 2 = ¬( S 1 ∧ ¬ S 2 ). We start with the denotation of the consequent S 2 : his children get frightened.

S 2 =   ( ) ↠ (get ⋆ (λe.
presuppose (λy. children y (sel e)) (λy. assert (frightened y) (λ_.

η ⋆))))

Our next step will be computing ¬ S 2 . Dynamic negation is defined by boxing and then asserting the negation of the boxed proposition. We start by boxing S 2 , i.e. evaluating box S 2 .

We skip useFind, since, as before, it does not cancel any presupposition. Then maybeAccommodate will take the presupposition and consider the two alternatives: projecting this presupposition further down the projection line or accommodating it here, in the antecedent. In the last step, we commute get with introduce and assert using the equations from 7.2.5. This makes it more obvious that x is one of the available discourse referents for the pronoun his in the consequent. Assuming that this pronoun will actually resolve to x and not to some other referent (i.e. sel (angry x :: man x :: x :: e) = x), then the argument to presuppose will be λy. children y x, in which x occurs free.

The computation is nondeterministic and uses amb (+) to split into three possible interpretations:

• projecting the presupposition out of the conditional (the way of global accommodation)

• accommodating the presupposition at the level of the antecedent of the conditional (intermediate accommodation)

• accommodating the presupposition already at the level of the consequent of the conditional (local accommodation)

We continue by applying the box handler.

box ( get ⋆ (λe.

introduce ⋆ (λx.

assert (man x) (λ_. assert (angry x) (λ_.

(presuppose (λy. children y x) (λy. assert (¬(frightened y)) (λ_.

η ⋆)))

+ (introduce ⋆ (λy. assert (children y x) (λ_. assert (¬(frightened y)) (λ_.

η ⋆))))

+ (assert (¬(∃y. children y x ∧ frightened y)) (λ_. η ⋆))))))) ↞ ↠ box (introduce ⋆ (λx. assert (man x) (λ_.
assert (angry x) (λ_. presuppose (λy. children y x) (λy.

assert (¬(frightened y)) (λ_. η ⋆))))))
+ η (∃x. man x ∧ angry x ∧ ∃y. children y x ∧ ¬(frightened y))

+ η (∃x. man x ∧ angry x ∧ ¬(∃y. children y x ∧ frightened y))

↠ ∃ ≫ x. presuppose (λy. children y x) (λy. η (man x ∧ angry x ∧ ¬(frightened y)))

+ η (∃x. man x ∧ angry x ∧ ∃y. children y x ∧ ¬(frightened y)) + η (∃x. man x ∧ angry x ∧ ¬(∃y. children y x ∧ frightened y))

As a result, we get two propositions and one stuck computation. The two propositions will (after negation) gives us the intermediate accommodation reading and the local accommodation reading, whereas the stuck computation represents the impossibility of the global accommodation reading.

The term ∃ ≫ x. presuppose (λy. children y x) M c is stuck, because when we expand ∃ ≫ , it becomes ∃ •≫ (C (λx. presuppose (λy. children y x) M c )). There is no rule in λ to reduce C (λx. presuppose M p M c ) when x occurs free in M p and the λ denotational semantics would assign ⊥ to this expression.

We finish computing the denotation of Example 26 by wrapping up the dynamic negation: negating and asserting the propositions. + (assert! (∀x. (man x ∧ angry x) → (∃y. children y x ∧ frightened y))) In the steps above, we pass the ≫= operator through the amb operation symbol, which is represented by +. We then perform the negation and assertion on the two successful computations. We also change the resulting propositions into equivalent but more readable ones. The resulting denotation is a nondeterministic computation that can either produce the intermediate accommodation reading ("If a man who has children gets angry, then his children get frightened"), the local accommodation reading ("If a man gets angry, then he also has children who get frightened") or get stuck. The PGA principle holds here since the intermediate accommodation reading is preferred to the local accommodation one.

- S 1 S 2 = ¬( S 1 ∧ ¬ S 2 ) = box ( S 1 ∧ ¬ S 2 ) ≫= (λa. assert! (¬a)) ↠ (∃ ≫ x.
We can write a handler that will recover the reading where the presupposition projects as far as possible without getting blocked by a binding. Our operation symbol for nondeterminism was called amb because of its similarity to McCarthy's amb operator for writing ambiguous (i.e. nondeterministic) functions [92, 4]. The expression C[amb(M, N )] reduces to either C[M ] or C[N ], ensuring that the 139 Here we are making use of the following rule: (A + B) ≫= F → (A ≫= F ) + (B ≫= F ). However, this rule is not derivable in λ . The A + B is de-sugared into two parts: the amb operation and an if expression (case analysis). The op.≫= rule lets us move the ≫= under the operation. However, we have no rule which lets us commute a ≫= (which is a handler) and case analysis (we will speak more about this in 9.3.1). Nevertheless, in this example, we permit ourselves to apply this rule as it does not affect the denotation of the term nor the final value and makes the notation a bit more bearable. If we were stricter, we would not be able to proceed with the ≫= until after we have selected the preferred reading using the search handler that we will present next.

resulting expression successfully produces a value. This kind of choice operator is sometimes called "angelic" because it watches out for us by making choices that will lead to a successful evaluation. This is the kind of oversight we need in our choice operator as well. Consider the presuppose clause of the maybeAccommodate handler: maybeAccommodate = presuppose: (λP k. presuppose P k + introduce ⋆ (λx. assert (P x) k))

Neither presuppose P k nor introduce ⋆ (λx. assert (P x) k) are stuck computations, but if in some larger context we decide to choose, e.g., the former, we might end up being stuck. This was the case in the denotation of Example 26: we decided twice to project the presupposition and later, when we applied the box handler, we were stuck.

The amb operator can be implemented in Scheme using continuations [122] and so we should be able to do the same using effects and handlers in λ . We will give amb the following semantics:

C[amb(M, N )] reduces to C[M ] if C[M ]
reduces to a value; otherwise, C[amb(M, N )] reduces to N . Our choice operator will be left-leaning, preferring to take the first choice but accepting the second if the first one leads to a failure. This way, we can encode a notion of preference into the choices. As when implementing shift in Chapter 4, we will use an operation for the amb operator, the amb operation symbol, written using +, and a handler to delimit the context C whose result we do not want to get stuck.

search : F E⊎{amb} (α) → F E (α) search = amb: (λ_k. k T; k F)
In the above, we use a new construction M ; N . The amb operator considers the result of a decision inside some context and then checks whether the result is a success or not in order to decide. The provisioning of the context is handled by search, whereas checking whether a computation is stuck is done by the M ; N construction. The idea behind M ; N is that M ; N should reduce to N if M is stuck; otherwise, it should reduce to M . We will give a formal definition shortly.

If we apply this handler to the denotation of Example 26, we will get the intended reading: the one in which the presupposition projects as widely as possible without violating binding. 140 search - S 1 S 2 ↠ search ( ((∃ ≫ x. presuppose (λy. children y x) (λy.

Identifying Stuck Computations

We will now give a formal semantics to the M ; N construction. We will not specify the reduction relation as a reduction rule using pattern matching because stuck computations are not easy to distinguish syntactically. The stuck redex can be buried deep within the term M and even if M contains a stuck redex, it is possible that this redex might disappear through some other reduction and therefore not cause the resulting computation to get stuck. Instead of identifying stuck computations syntactically, we will use our denotational semantics from 3.3.1, which already identifies stuck computations with ⊥. However, the constructors for computation types are not strict. If their arguments are ⊥, the results do not have to be (e.g. if M (e) = ⊥, then η M (e) = η(⊥) ̸ = ⊥). We will consider a computation successful if it does not contain ⊥, a notion we define formally as being ⊥-less. But first, we give the typing rule for M ; N expressions.

Definition 7.3.1. The types of M ; N are given by the following inference rule:

Γ ⊢ M : α Γ ⊢ N : α [; ] Γ ⊢ M ; N : α Definition 7.3.2.
For every λ type τ , we define a predicate "is ⊥-less" on the domain of τ , τ .

By induction on the structure of type τ :

• x ∈ ν is ⊥-less if x ̸ = ⊥ • f ∈ α → β is ⊥-less if f ̸ = ⊥ and for every ⊥-less x ∈ α , f (x) is ⊥-less • e ∈ F E (γ) , by induction on the structure of e -⊥ is not ⊥-less -η(x) is ⊥-less if x is ⊥-less -op(p, c) is ⊥-less if p is ⊥-
= C[R] with R → ; R ′ (c = M ; C[R ′ ])
We will choose d = M . This case is symmetric to the previous one where we have M ; N reducing to one branch and the inner reduction happening in the abandoned branch.

• b = N and N = C[R] with R → ; R ′ (c = M ; C[R ′ ]) We will choose d = C[R ′ ].
This case is symmetric to the first one in which the inner reduction (R → ; R ′ ) happens in the chosen branch (M in the first case, N in this one).

4. If the redex in a → ; c is the entire term a and the redex in a → ; b is a proper subterm of a:

Symmetric to the previous case. Proof. As in the proof of Lemma 3.4.17, we will make us of Hindley's Lemma 3.4.16. We will be proving that for every λ ; terms a, b, c such that a → λ b and a → ; c, there exists a d such that b ↠ ; d and c → = λ d. The proof will be analogous to the one of Lemma 3.4.17, proceeding by induction on the structure of a and considering the relative positions of the redexes in the reductions a → λ b and a → ; c.

• If both reductions occur in a proper subterm of a, then we use the induction hypothesis and the context closure of the two relations.

• If the reductions occur in non-overlapping subterms of a, then the common reduct d is a term in which both subterms have been reduced.

• If the redex in a → λ b is the entire term a and the redex in a → ; c is some proper subterm of a:

Let l → r be the λ rule used in a → λ b. None of the left-hand sides of the reduction rules in λ contain the semicolon operator and so the ;-redex in a must be matched by some metavariable in l.

Let M be that metavariable. We decompose the left-hand side l into L(M ) and the right-hand side r into R(M ). We have a = L(a ′ ), b = R(a ′ ) and a ′ → ; a ′′ with c = L(a ′′ ) for some a ′ and a ′′ . Our common reduct d will be R(a ′′ ). For b, we have b = R(a ′ ) ↠ ; R(a ′′ ) = d by a → ; a ′ and the context closure of → ; . Note that R(a ′ ) might contain multiple copies of a ′ or maybe even no copies of a ′ (as is the case when rules copy or delete terms). No matter the number of copies, we always have R(a ′ ) ↠ ; R(a ′′ ), because ↠ ; is reflexive and transitive. For c, we have c = L(a ′′ ) → λ R(a ′′ ) = d because L(a ′′ ) → R(a ′′ ) is an instance of the λ rule l → r.

• If the redex in a → ; c is the entire term a and the redex in a → λ b is some proper subterm of a:

Let a = M ; N . We proceed the same way as in case 3 in the proof of Lemma 7.3.8. We have an outer ;-reduction and an inner denotation-preserving reduction. Performing the inner reduction a → λ b first does not change the denotation and so we can still apply the ;-reduction b → ; d.

Performing the outer reduction a → ; c first either throws away the redex for the λ reduction and so we have c = d, or it preserves it whole and then we can still perform the reduction c → λ d.

• a is at the same time a λ -redex and a ;-redex: This is impossible because there is no rule in λ whose left-hand side is headed by the M ; N construction, which is, on the other hand, the case in every ;-redex.

Comparison with TTDL

The C construction introduced partiality to λ . With the M ; N construction in our calculus, we now have a way to react to partiality, to avoid stuck terms. We have seen how to use that feature together with effects and handlers to implement McCarthy's ambiguous operator amb and then use that to implement the presupposition accommodation strategy used in Lebedeva's extension of TTDL [80], which projects presupposition as widely as possible without breaking variable binding. Our solution improves in some aspects on Lebedeva's work:

• The underlying calculus is strongly normalizing.

Lebedeva extends the simply-typed λ-calculus with (unrestricted) exceptions and the resulting calculus is non-terminating, as shown by Lillibridge's encoding of recursive types [85]. Our first attempt at formalizing λ actually had the same deficiency and we were able to encode recursive types using Lillibridge's method. 142 Furthermore, when Lebedeva sketched out a possible solution to the binding problem, she defined a recursive function which was then part of the lexical semantic entries. 143 This is also problematic since general recursion precludes termination. Our calculus gets around this by relying on inductive types to provide a limited form of recursion which can be proven terminating.

The λ calculus, as it is presented in this manuscript, is terminating and strongly normalizing, while still allowing us to implement the accommodation strategy used by van der Sandt [130] and Lebedeva [80].

• Our analysis fixes a bug which allowed presupposition triggers to bind pronouns preceding them.

The exceptions used in Lebedeva's extension of the simply-typed λ-calculus are not resumable. If a referential noun phrase triggers a presupposition about the existence of its referent, the evaluation of the sentence is restarted with the presupposed referent now in the context. However, this overgenerates by allowing any anaphoric expressions in the same sentence to bind to that referent, even those expressions which precede the presupposition trigger. The operations in λ are resumable exceptions. Since we can resume the interpretation of a sentence after accommodating the presupposition, we do not have to restart the evaluation of the sentence and therefore we avoid the above situation.

• We treat presuppositions using the same formal apparatus as dynamics and anaphora.

Lebedeva uses terms to encode dynamic propositions, following de Groote's schema [38]. The terms and their types correspond to a monad of state and continuations. When this theory is then extended to cover presuppositions, instead of augmenting the monad to include another effect, the underlying λ-calculus is replaced by an impure calculus with order of evaluation, exceptions and handlers.

Our approach is based on and heavily inspired by Lebedeva's use of exception mechanisms to treat presupposition but instead of using a term encoding for dynamicity and side effects, such as exceptions, for presupposition, we use a free monad for everything. 144 Our free monad is a term encoding of a computation, much like de Groote's original approach was a term encoding of a dynamic proposition, which means that our calculus has no fixed order of evaluation (i.e. is pure). The free monad lets us combine both the dynamic effects of manipulating a state and a continuation together with the effect of throwing exceptions for presuppositions in a single encoding with relative ease.

Double Negation

We now turn our attention to another extension of TTDL. In his thesis [111], Sai Qian considers examples such as the following one from Barbara Partee [112]:

(28) Either there's no bathroom 1 in the house, or it's 1 in a funny place.

The bathroom mentioned in the first clause is embedded under a negation but nevertheless, we can still access it in the second clause. If we look at the disjunction A ∨ B in DRT and TTDL, it has the same truth conditions and accessibility characteristics as ¬(¬ A ∧ ¬ B). This is how TTDL defines dynamic disjunction. If we take the meaning of there's no bathroom to be ¬ A ′ where A ′ is the meaning of there is a bathroom, then the meaning of Example 28 comes out as:

¬ A ′ ∨ B = ¬(¬(¬ A ′ ) ∧ ¬ B)
In classical logic, we may use the law of double negation to go from ¬(¬ A ′ ) to A ′ .

¬(¬(¬

A ′ ) ∧ ¬ B) = ¬(A ′ ∧ ¬ B) = A ′ → B
If we do so, the dynamic contributions of A ′ will no longer be blocked by a negation and will become accessible to any anaphoric pronouns in B. As we see above, the sentence ends up being paraphrased as "if there's a bathroom, then it's in a funny place".

In order for this line of reasoning to hold within the framework, we would need the law of double negation to hold. However, that is not the case in neither DRT nor TTDL. For DRT, this problem is addressed by Krahmer and Muskens in Double Negation DRT (DN-DRT) [78] and for TTDL with a very similar strategy by Qian in Double Negation TTDL (DN-TTDL) [111].

The DN-TTDL approach is an instance of the following general strategy. Let us imagine we have some set A (e.g. the set of DRSs or TTDL dynamic propositions) and a function f : A → A (e.g. negation) that we would like to adapt into some involution g. 145 Applying g to a value once should have the same (or somehow similar) effect as applying f once (i.e. g should simulate/extend f ). Furthermore, applying g twice must act as the identity function. We can consider an extended domain A × A and for each value x ∈ A pairs i(x) of the form ⟨x, f (x)⟩. The swapping operation λ ⟨a, b⟩ . ⟨b, a⟩ is then just the function g we were looking for. We have the following:

π 1 (i(x)) = x π 1 (g(i(x))) = f (x) π 1 (g(g(i(x)))) = π 1 (i(x)) = x
The first equation shows us that the i injection is a right inverse to the π 1 projection. The second equation shows us that using g in the extended domain A × A is exactly like using f in the original domain A. Finally, the third equation shows us that g is an involution. This is exactly the approach adopted by Qian in [111]. The original domain is the type of dynamic propositions Ω = γ → (γ → o) → o and the function f is TTDL's dynamic negation. The domain of DN-TTDL is defined as the type Ω × Ω, propositions are injected from TTDL to DN-TTDL using i(x) = ⟨x, f (x)⟩ and DN-TTDL dynamic negation works by swapping the two elements of the pair. We can conceive of this pair as the positive and negative representation of a proposition, the second item of the pair always being a negated form of the first one.

DN-DRT [78] adopts a similar strategy. Two interpretation functions are given: one for positive readings and another for negative readings. Negation becomes a new constructor for DRSs, its positive interpretation being the negative interpretation of its argument and its negative interpretation being the positive interpretation of its argument. Therefore, every DRS has two interpretations and negation is implemented as exchanging these two interpretations.

Double Negation as an Effect

Our methodology is built on the assumption that the phenomena that we treat using effects have a projective nature. If a certain construction does not play a role in the phenomenon, it should transfer any operations related to this phenomenon from its arguments up to its context. For example:

• An indefinite noun phrase like a man introduces a new discourse referent x along with the condition man x. If this NP becomes an argument of a verb, then the verb applies itself to the NP's referent and transfers these dynamic effects up to the nearest enclosing box. The meaning of a man sleeps still introduces a new discourse referent x along with the condition man x while also introducing the condition sleep x. Since the verb had no interaction with dynamicity, all of the NP's effects were preserved.

• An anaphoric pronoun such as he accesses the context to find its antecedent x. Applying the predicate sleeps preserves this context dependence and yields a computation that also starts by accessing the context to find an antecedent x and then producing the proposition sleep x. Deictic and intensional meanings access some external information to find their referents as well and they behave the same in these scenarios.

• A definite description such as the king of France presupposes the existence of a king of France x and again, we can compute the meaning of the king of France is bald by applying the predicate bald to the referent x while still presupposing the existence of the king of France x.

Lexical items that want to interact with a certain phenomenon, a certain level of meaning, do so by either signalling an operation or handling one. The entries of all the other lexical items which are not involved in this phenomenon do not have to be modified in any way and they project these requests automatically. As we have seen in the last two chapters, for many phenomena this is the case. This way, semantics of deictic NPs are not affected by the existence of anaphoric NPs or presuppositional NPs, and neither of these affect the semantics of simple predicates (e.g. extensional transitive verbs denoting relations on individuals such as loves).

Now when we look at the treatment of double negation as an effect, it does not follow the same pattern. The change in types in TTDL is from Ω to Ω × Ω. If we want to treat this as an effect, we can look at monads which employ similar types. Two come to mind: the writer monad that maps the type α to α × Ω and the reader monad that maps the type α to 2 → α.

Polarity Sensitivity -Reader Monad

In the reader monad approach, we look at the type Ω × Ω as a family of dynamic propositions of type Ω indexed by the type 2 (i.e. Ω × Ω ≃ 2 → Ω). These computations live in some context in which they have access to a polarity of type 2 and based on that polarity, they should either return a positive version of themselves or a negative one. The corresponding operation would be something like get_polarity : 1 ↣ 2. We will see that such an approach is problematic.

Let us look at the VP "trusts nobody" whose meaning is a function from individuals to polaritysensitive propositions, that when given an individual x will ask for the polarity and if it is positive, return "x trusts nobody", and if it is negative, return "x trusts somebody". If we then embed this VP inside the sentence "I met a man who trusts nobody", the resulting meaning would ask for the polarity and if it is positive, return the meaning of "I met a man who trusts nobody", and if it is negative, return "I met a man who trusts somebody", which is not the desired negation of the sentence. We do not get the correct meaning by ignoring the get_polarity operation and applying the meaning of the context "I met a man who []" to (either of) the results.

If a proposition occurs in some context which is not a negation, then it appears with positive polarity and we should apply a handler which signals that. However, we would have to include this handler in all lexical entries that embed other propositions as arguments, which would defeat the point of our method. Futhermore, if we would end up implementing negation as a handler that switches polarity, then we would be obliged to also change all lexical entries that produce propositions so that they do not forget to ask for polarity. The η injection of the reader monad maps a dynamic proposition A to a function λp. A, which ignores the polarity p and assigns the dynamic proposition A to both. This is clearly not what we want as it ends up making every dynamic proposition equal to its negation.

Providing Negations -Writer Monad

The writer monad is about computations outputting something: in our case they would be outputting their suggested negations, as in the technique for building up involutions using pairs shown above. This would correspond to some operation negative : Ω ↣ 1 with which a proposition would suggest to its context a preferred negation that ought to be used if someone would try to negate it.

In this case, the VP "trusts nobody" would be a function from individuals x to dynamic propositions "x trusts nobody" that would suggest "x trusts somebody" as their negation. If we then look at the complex sentence "I met a man who trusts nobody", its meaning would be a computation that produces the meaning of "I met a man x who trusts nobody" but also suggests that "x trusts somebody" is its negation. Again, it becomes incorrect to ignore the negative effect in constructions that embed propositions. Furthermore, what would be the semantics if a proposition used the negative effect multiple times? The writer monad expects the type of the material being to form a monoid, which would be difficult to arrange in our case.

DN-TTDL is Not Monadic

So far, we have tried taking existing monads which superficially look like DN-TTDL (i.e. they use the same types) and we have seen that neither models the semantics of DN-TTDL faithfully, forcing us to explicitly introduce handlers in all lexical entries that work with propositions, forfeiting the benefit of using λ computations in the first place. In this and the next subsection, we will try to find out why monads and effects are not a good fit for DN-TTDL.

We will start by showing that the constructions in DN-TTDL are not monadic. We have seen the definition of a monad in 3.3.6: we need to provide a functor F and the combinators η and ≫= which satisfy the monad laws.

F (Ω) = Ω × Ω η A = ⟨A, ¬ A⟩ A ≫= f = f (π 1 A)
This captures the idea behind the DN-TTDL approach:

• the type of propositions is generalized to become the type of pairs of positive and negative propositions,

• older values (simple dynamic propositions) are lifted by creating pairs in which the second item corresponds to the dynamic negation of the original value

• if we want to apply a function f on some DN-TTDL proposition, we extract its positive variant and use that as the argument of f

We can check that our translation is faithful by trying to use the two combinators above to automatically raise operators such as dynamic conjunction into the new double-negation theory. We can reuse the general monadic lifting functions from 6.1.

lift L α-•β-•γ : ( α → β → γ ) → (F ( α ) → F ( β ) → F ( γ )) lift L α-•β-•γ f = λXY. X ≫= (λx. Y ≫= (λy. η (f x y))) = λXY. ⟨f (π 1 X) (π 1 Y ), ¬(f (π 1 X) (π 1 Y ))⟩ lift L S-•S-•S (∧) = λXY. ⟨(π 1 X) ∧ (π 1 Y ), ¬((π 1 X) ∧ (π 1 Y ))⟩
By applying lift L S-•S-•S to dynamic conjunction, we arrive at the extended definition of conjunction used by Qian in [111]. Thus we manage to derive from the general monadic lifting function and the two lines that define η and ≫= for this monad the same operator that Qian introduced in his thesis. This seems to suggest that this translation is indeed a faithful one.

However, there are two problems with the "monad" we just introduced. First of all, η is not general and is only applicable to values of type Ω (dynamic propositions). It begs the question what would be the interpretation of types such as F (ι), i.e. what is the negation of an individual. Secondly, even if we ignore this and just stay in the domain of dynamic propositions, permitting only types F (Ω), we run into a more severe problem. The "monad" that we proposed does not actually satisfy the right identity law (Law (3.12)).

X ≫= η = X The reason is simple. The ≫= operator forgets about the negative form of X and then η replaces that negative form with the default one produced by dynamic negation. The two terms are thus not equal, since the one on the left replaces the proposed negative form X with the default dynamic negation.

In our method, we model denotations as λ computations and λ computations form a monad, i.e. for any effect signature E, ⟨F E , η, ≫=⟩ is a monad. Likewise, all of the phenomena we treat have a monadic structure as well: Barker's continuization uses the continuation monad [12], de Groote and Lebedeva's TTDL uses a combination of the state monad and the continuation monad [38, 80] (see Subsection 5.4.2), de Groote and Kanazawa's intensionalization uses the reader monad [40], Giorgolo and Asudeh's implementation of Potts' conventional implicature analysis uses the writer monad [51]. The fact that the structure used by Qian [111] is not a monad could be a reason why its implementation using λ effects is difficult.

We have shown that DN-TTDL is not monadic, but there are also other abstractions which have weaker laws than monads and which are still useful. The applicative functors (see Subsection 3.3.5) that are used in Oleg Kiselyov's Applicative Abstract Categorial Grammars [68, 69] are one such example. However, as we will show next, DN-TTDL also violates the laws of functors, which are even weaker than those of applicative functors.

DN-TTDL is Not Functorial

A functor F maps types α to types F (α) and functions f : α → β to functions F (f ) : F (α) → F (β). The functor underlying the almost-monad from the previous subsection is the following:

F (Ω) = Ω × Ω F (f ) = λX. ⟨f (π 1 X), ¬(f (π 1 X))⟩
Same as for the monad, this is still applicable only to functions whose return type is Ω. However, even if we ignore this, we find out that this structure does not satisfy the laws of a functor. Functors have to adhere to two laws: homomorphism w.r.t. to function composition and homomorphism w.r.t. to identities. It is the latter which this structure fails. Consider the identity law of functors (Law (3.5)):

F (id A ) = id F (A)
If we try to elaborate F (id Ω ) with this structure, we find that it does not correspond to an identity:

F (id Ω ) = λX. ⟨π 1 X, ¬(π 1 X)⟩ id F (Ω) = λX. ⟨π 1 X, π 2 X⟩ F (id Ω ) ̸ = id F (Ω)
Therefore, the structure in DN-TTDL is not a functor and by extension neither an applicative functor. The failure in the functor identity law highlights why this kind of strategy is incompatible with our approach. It is exactly because of the fact that the negative variants of propositions are not things that project -if A n is the negative variant of A, that does not mean that A n is the negative variant of A ∧ Bthat this structure breaks the functor laws. In order to stop the projection of the proposed negative variant out of a context, the functor forgets the old negative variant and replaces it with a new one. However, this kind of behavior that suppresses this extra information is non-functorial, since if we apply the functor to the identity function, we get a function that forgets the extra annotation (the negative variant) and therefore we do not have an identity function.

When we say that this solution to the double negation problem is incompatible with our approach, we mean that we cannot find effects that implement this kind of functionality. However, this does not mean that we cannot combine our technique of using λ computations with the technique proposed by Qian [111]. We have seen how to implement TTDL in λ , on which DN-TTDL is built. We can therefore use the DN-TTDL schema while replacing the TTDL implementation with our λ implementation. The downside is that we have to then always work with pairs of computations of propositions everywhere, which is a heavy price to pay for the offered empirical coverage increase.

Summary

In this chapter, we have seen how to implement dynamic semantics in the λ framework. Our goal was to motivate a core set of operations which characterize dynamic meanings. In order to do that, we have taken DRT, a well-established theory of dynamic semantics, and shown how its canonical formulation in Kamp and Reyle's textbook [64] can be seen as a collection of effectful programs (7.1). This validated our intuition that dynamic semantics can be suitably modelled as effectful computation and also shown us what effect signature to choose and how to use those effects to give denotations to lexical items in our grammar (7.2). In translating the DRT fragment into an ACG+ λ fragment, we have made it compositional by showing that what DRT actually composes are instructions on how to build DRSs. We have then connected our analysis to de Groote's Type-Theoretic Dynamic Logic [38, 80] by interpreting the computations as dynamic propositions. Finally, inspired by the algebraic effects literature [60, 103, 110, 104], we have given a system of equations which derives DRSs as the canonical forms of dynamic computations (a collection of variables accessible to subsequent formulas coupled with a collection of simple propositions about those variables) (7.2.5).

After having introduced anaphora, we moved onto another effect that is closely related: presuppositions (7.3). Our treatment of presuppositions, which was in the style of Lebedeva [80] and van der Sandt [130], was built on top of our dynamic semantics and was the first time we got to see how to combine side effects from different phenomena. We first started with changing the dynamic effects handler from a closed handler into an open one (7.3.1). While this involved some complicated λ-terms, this is a price we will have to pay only once. Now that we have an open handler for dynamics, we can combine dynamics with other effects with much less effort.

Then we took the following steps to integrate presuppositions into our dynamic semantics:

1. We have fixed a bug in the dynamics handler (box) which relied on the assumption that the contents of DRSs higher up on the projection line than the closest immediate DRS will not change; an assumption that would be invalidated by the introduction of presuppositions (7.3.1). While without fixing this, our analysis was undergenerating, Lebedeva's analysis [80] suffers from a similar bug and is overgenerating (licensing the reading "He 1 loves John's 1 car").

2. We introduced a new operation presuppose : (ι → o) ↣ ι and used it in lexical entries such as  for proper names and  for possessive constructions.

3. We introduced a handler for presuppose called accommodate and we added it to a handler representing the top-level DRS. At this point, we could analyze discourses such as Example 20, repeated below, which were not covered by the original TTDL [38] and which motivated the use of exceptions in Lebedeva's extension [80].

(20) It is not the case that Jones 1 owns a Porsche. He 1 owns a Mercedes.

4. We introduced a new handler, useFind, that tried resolving presuppositions by looking up the referent in the context instead of always presupposing its existence, as in [80]. This let us analyze cases such as Example 22 without projecting a presupposition. (22) If John owns a car, then his car is cheap.

5. We enriched the box handler with a clause for nondeterministically accommodating presuppositions, maybeAccommodate. This allowed us to account for the ambiguity inherent in the accommodation of presuppositions, such as in Example 24:

(24) (c 0 ) Maybe (c 1 ) Wilma thinks that (c 2 ) her husband is having an affair.

6. We have encoded the Preference for Global Accommodation principle and its binding problem constraint by introducing an operator to λ for identifying stuck computations and by writing a handler for nondeterministic choice that gave it the semantics of McCarthy's amb operator [92].

With this, we analyzed Example 26:

(26) (c 0 ) If (c 1 ) a man gets angry, (c 2 ) his children get frightened.

Notably, we did not need to touch the dynamic denotations that we have developed in 7.2 in order to make them presupposition-compatible. We only modified dynamic negation, ¬, by adding new clauses to the box handler to implement the interaction between DRSs and presuppositions. Our objective was to have empirical parity with Lebedeva's analysis [80] while using the same mechanism to implement both dynamics and presuppositions ( λ computations) and without having to use a calculus with a non-standard evaluation order. In this, we have succeeded146 and we have also shown an example in which we can overcome an empirical limitation of Lebedeva's approach.

Finally, we addressed another extension of TTDL, Qian's DN-TTDL [111]. We have analyzed his proposal and shown that it is out of the scope of our approach as it involves a non-functorial structure at its core. While we cannot translate Qian's technique into effects and handlers, we can use his technique directly to model propositions as pairs of computations. As this would be a heavy change to our fragment, we avoid this technique in the rest of the manuscript.

Composing the Effects

In Chapters 6 and 7, we have seen λ analyses of deixis (6.2), conventional implicature (6.3), quantification (6.4), anaphora (7.2) and presupposition (7.3). All of those analyses shared the same structure: constituents of atomic abstract type were interpreted as λ computations. 147 The fact that there is a common underlying structure present in all of these phenomena has already been discovered by the pioneers of monads in natural language semantics [113, 27, 50, 13]. However, the point of expressing all of these phenomena in a single framework is not just to have a uniform set of fragments, but to also be able to combine those fragments into a wider picture.

Most recently, proposals for combining monads in natural language semantics have started appearing [27, 50, 13]. We can divide them into two strategies:

• Constructing a "supermonad" that combines the structural elements of all the monads that we want to use.

The denotations of constituents are then all computations within this monad (or their denotations are injected into this supermonad). The monad's ≫= operator serves as the universal glue, allowing us to combine any two meanings, regardless of the effects they use. This approach was adopted by Charlow in his dissertation [27].

• Making all the necessary components to build semantic glue lexical items in the grammar.

Instead of deriving a general monad that encompasses all of the necessary monadic structure, we include the η and ≫= of every monad we want to use into our grammar. Different lexical entries will use different (combinations of) monads and it is one of the duties of parsing to find the necessary semantic glue which combines these meanings in a sound way. This approach was proposed by Giorgolo and Asudeh in their ESSLLI 2015 course [50] and by Charlow in Barker's ESSLLI 2015 course [13, 31].

Since ACGs separate the object-level types (where we use monads and semantic types) from the abstract-level types (where we use linear implications and syntactic types and where we control the set of valid syntactic structures), the latter approach becomes impractical. If we wanted to add the monadic combinators η and ≫= and give them their correct types, we would need to change the logic of the abstract-level type system, e.g. by including a modality for every monad. In doing this, we would no longer be working with ACGs, but with some other type-logical grammar formalism, and we would lose the benefit of existing results for ACGs (e.g. on the complexity of parsing [65]). Our approach is an instance of the former method. Our "supermonad" is the free monad F E from 3.3.6 and 3.3.7. In contrast to the approach used in Charlow's dissertation [27], we explore the use of effects and handlers instead of monad transformers and we perform all computation in a formally defined object language λ , which is an extension of the simply-typed λ-calculus. This grammar is about dynamic semantics and anaphora. Therefore, it contains indefinites (indefinite article + common nouns) and pronouns to showcase the introduction and retrieval of discourse referents. It also contains entries for verbs which let use these noun phrases inside of sentences. One of the key issues of dynamic semantics is how anaphora interacts with logical operators. For these purposes, we include in our grammar lexical items corresponding to constructions that mimic the logical operators of negation, conjunction, implication and disjunction. Finally, dynamic semantics studies how anaphora works across sentences, through a discourse. We treat discourse as a list of sentences. We introduce an atomic abstract type D of discourses, an empty discourse  : D and a discourse extension operator _._ : D -• S -• D.

We will now give a semantic interpretation to the abstract language generated by these items. First, we define the object signature that will be the target of our interpretation.

_ : ι → γ → γ _ :: _ : o → γ → γ _ + + _ : γ → γ → γ sel he , sel she , sel it : γ → ι
We will have a type o of propositions, which will be built out of first-order logic (FOL) formulas. We include constants for all FOL constructors: tautology (⊤), contradiction (⊥), negation (¬), conjunction (∧), implication (→), disjunction (∨), existential quantification (∃), universal quantification (∀), equality on terms (=), unary predicates (corresponding to common nouns) and binary predicates (corresponding to transitive verbs). We aim to treat anaphoric binding but not anaphora resolution, and so we introduce constants for operations that will perform anaphora resolution: the oracles sel he , sel she and sel it . 149 The anaphora resolution operators work on contexts, which contain all the knowledge in the common ground and all individuals available for discussion. These contexts, of type γ, are built up using nil, :: and + +, where :: is overloaded to work both for individuals and propositions. Now that we have defined the object signature into which we want to interpret our abstract language, we are ready to lay down the lexicon. We interpret the atomic abstract types as computations:

Dynamic Kernel

205

In the interpretations, we make use of dynamic logical operators that work with propositions of type F E (1), most of which we have seen in Chapter 7. Below, we give the definition for the complete set of first-order dynamic logical operators:

A ∧ B = A ≫= (λ_. B) ¬ A = box A ≫= (λa. assert! (¬a)) ∃ x. A = introduce ⋆ (λx. A) A → B = ¬(A ∧ ¬ B) A ∨ B = ¬(¬ A ∧ ¬ B) ∀ x. A = ¬(∃ x. ¬ A)
From their definitions, we can glean some of the dynamic characteristics of these operators:

• In A ∧ B, the effects of A combine with and scope over the effects of B. The discourse referents introduced by A are therefore accessible in B, i.e. ∧ is an internally dynamic operator.

• The existential quantifier ∃ : (ι → F E (1)) → F E (1) uses the introduce operation to scope over its continuation. This, in combination with the previous fact, allows us to derive the key law of dynamic logic (∃ x. A) ∧ B = (∃ x. A ∧ B).151

• The ¬ A dynamic negation uses the box handler to interpret the dynamic operations in A and therefore stop their projection. This makes ¬ an externally static operator since the dynamic effects of its argument do not project (i.e. are not accessible) out of the resulting proposition.

• The last three operators are all headed by ¬ and are therefore all externally static.

• The left conjunct in the definition of A ∨ B is negated and ∨ is therefore internally static (discourse contributions of A are not accessible in B). On the other hand, the left conjunct in the definition of A → B is not negated and → is therefore internally dynamic (as in the example "If John owns a car 1 , then it 1 is cheap").

The final piece of the puzzle is the box handler, which we have defined in 7.

(λ_. η (λe. ⊤)) A) ≪• nil _ ≪• _ : F E (α → F E (β)) → α → F E (β) F ≪• x = F ≫= (λf. f x) ∃ ≫ : (ι → F E (o)) → F E (o) ∃ ≫ P = ∃ •≫ (C P )
We have described the evolution of this handler in Chapter 7, so we will not go through the details again. We will highlight just one thing, in connection to the definition of ∃ above. The ∃ uses the introduce operation and the reduction rule op.≫= tells us that operations project out of computations (op M p (λx. M c ) ≫= N → op.≫= op M p (λx. M c ≫= N )). The box handler replaces the introduce operation • introduce i adds discourse referents to the implicature layer • presuppose adds discourse referents and conditions to the presupposition layer We can compare the layered DRS with the corresponding computation. Geurts and Maier [46] give the following layered DRS as the meaning of Example 30. (30) The porridge is warm.

x p porridge p (x)
warm a (x)

¬ i hot i (x)
presuppose porridge (λp. assert (warm(x)) (λ_.

implicate (¬(hot(x))) (λ_.

η ⋆)))
However, our use of distinct operation symbols for assertions, implicatures and presuppositions was not motivated by the separation of these layers of meaning, but by their different projectional behavior. In that, our approach is closer to Projective DRT. In Projective DRT, the DRSs are labelled and every discourse referent and condition is annotated with a pointer which either points to a label or is free. Assertions point to the containing DRS while conventional implicatures point to the topmost DRS. Presuppositions either point to a local/intermediate DRS when the presupposition is bound ("cancelled"), or they are free, in which case they project and accommodate in the topmost DRS.

1 f ← x f ← porridge(x) 1 ← warm(x) 0 ← ¬ 2 2 ← hot(x)
presuppose porridge (λp. assert (warm(x)) (λ_.

implicate (¬(hot(x))) (λ_.

η ⋆)))

The correspondence between Projective DRT and our approach is similar to the one with Layered DRT. Material addressed to the global DRS 0 is analysed as implicature (implicate and introduce i ), material addressed to the DRS in which it appears is treated as assertion (assert and introduce) and material that is addressed to some free label f is treated as presupposition (presuppose). Projective DRSs might also contain pointers to labels which are neither local nor global. These presumably correspond to bound/cancelled presuppositions, which our approach treats by retrieving the presupposed referent from the context. The pointers that appear next to discourse referents and conditions faithfully describe the way that our approach will project and accommodate them:

• implicatures (pointers to 0) use implicate and introduce i and therefore project all the way to the top handler

• assertions (pointers to the enclosing DRS) use assert and introduce and are therefore handled by the nearest enclosing box handler

• presuppositions (free pointers) use presuppose and can therefore be bound at any box thanks to the useFind handler (see 7.3.3) or accommodated at the top thanks to the accommodate handler (or even accommodated lower due to binding constraints, see 7.3.4)

Adding Deixis

We now move to our treatment of indexical expressions, namely of the first-person pronoun. We will be enriching the abstract signature with a new constant representing the pronoun as well as verbs for reported speech. The semantics of  are exactly the same as the original ones in Section 6.2 and so is the withSpeaker handler. We also extend the top handler so that it still covers all the effects in our grammar. However, unlike with the dynamics, where we could use the handler to supply an "out-of-the-blue" context, it is more difficult to identify a default speaker. Therefore, we add an argument to top so that if someone is to recover the meaning of a sentence in our growing fragment, they will have to identify the speaker.

Finally, we will examine the entries for reported speech. Again, we have differences due to our use of side effects to convey truth conditions:

• the propositions generated by the say predicate need to be asserted

• the quoted sentence is evaluated down to a proposition using box Then we have an important difference in the   entry for direct speech:

• we want to bind the speaker to the referent of the subject, s, using withSpeaker s

• we want to use box to evaluate the clause down to a proposition, same as for the   entry • we do not want pronouns or other anaphoric elements within the quoted sentence to be bound by referents from the quoting context and so we use the empty handler (see 8.1)154

• we do not want the presuppositions triggered by the quoted sentence to be considered as presuppositions of the report and so we accommodate them within the scope of say

• we also do not want the same to happen for implicatures and so we use the withImplicatures handler to ascribe them to the person being quoted

In the end, what we want is to apply a handler for all of the effects that we have introduced so far. Since we have defined the composition of all these handlers as the combinator top, we can use that in the lexical entry for   . The intuition behind it is that a directly quoted sentence does not get to have any of its usual linguistic effects.

Adding Quantification

We finish extending our fragment by adding the last of the phenomena that we have studied in Chapter 6, (in-situ) quantification. We add into our fragment the determiners every and a,155 as well as a genitive construction with a relational noun156 (owner) so that we can experiment with quantifiers embedded within quantifiers. , ' : N -• N P - : N P -• N

The object signature already contains the necessary logical material to interpret these new lexical items (logical operators and quantifiers for the determiners and the own relation for the relational noun). To account for how quantified noun phrases take scope over their context, we will be using the scope operator, as in Section 6.4.

scope : ((ι → F E ′ (1)) → F E ′ (1)) ↣ ι Its type has changed from ((ι → o) → o) ↣ ι to ((ι → F E ′ (1)) → F E ′ (1)
) ↣ ι to reflect the change due to using dynamic propositions F E ′ (1) instead of static propositions o. Also note that the effect signature that we refer to in the type of scope is E ′ . Throughout this chapter, we use E to mean the effect signature containing all the effects introduced so far. Now, we will be adding scope into the effect signature E. However, if we gave it the type ((ι → F E (1)) → F E (1)) ↣ ι, then we would be giving a circular definition of E: E is an effect signature which, among others, contains an effect scope :

((ι → F E (1)) → F E (1)) ↣ ι
, where E is an effect signature which, among others, contains an effect scope…. Therefore, we use a different effect signature in the type of scope, one that does not contain scope: E ′ = E \ {scope}. 157 We can now give the lexical entries for the determiners and the relational noun. These will follow the ones from Section 6.4, modulo the use of dynamic propositions (dynamic logical operators and quantifiers, assert). We can check the types of  and ' , namely their uses of scope. We know that the use of scope is allowed only when its argument is guaranteed not to use scope. The continuation k that we get from SI is guaranteed to be free of scope since SI will have handled any occurrences of scope within before passing it to our scope-taker. The denotation of the noun N can trigger its own effects, including scope, the noun take scope either below or above the quantifier of the determiner.

 1 = λN. scope! (λk. ∀ x. SI ((N ≪• x) ≫= assert!) → k x)  2 = λN. scope! (λk. SI (∀ x. ((N ≪• x) ≫= assert!) → k x))
We choose the entry which assigns scope that corresponds to the linear order of the determiners within the sentence. To account for the alternative readings, we will adopt the solution of quantifier raising from 6.4.1.

We can also check that the new entry for the indefinite article ' amounts to almost the same thing as the existing one for :158

SI ( ' N ) = SI (scope! (λk. ∃ x. SI ((N ≪• x) ≫= assert!) ∧ k x)) = ∃ x. SI ((N ≪• x) ≫= assert!) ∧ η x ≈ ∃ x. ((N ≪• x) ≫= assert!) ∧ η x = introduce ⋆ (λx. ((N ≪• x) ≫= assert!) ∧ η x) = introduce ⋆ (λx. (N ≫= (λn. assert! (n x))) ∧ η x) = introduce ⋆ (λx. (N ≫= (λn. assert! (n x))) ≫= (λ_. η x)) = introduce ⋆ (λx. N ≫= (λn. assert (n x) (λ_. η x))) =  N
Quantified noun phrases using the scope effect take scope over all the material up to the nearest enclosing SI handler. We should therefore modify some of the existing constructions in our grammar to use SI to designate scope islands. Notably, we will make it so that every tensed clause acts as a scope island by including SI in the lexical entries of tensed verbs.

Quantifier Raising -Inverse Scope and Crossover

The strategy that we have used in Subsection 6.4.1 to deal with quantifier scope ambiguity was to change the order of evaluation of the quantified noun phrases. This was the case both in the first approach, which considered adding different lexical items which evaluate their arguments in different orders, and in the second, final approach, which used a general operator QR to displace the evaluation of an N P .

However, freely changing the order of evaluation is problematic. Consider the following sentence (from [120]):

(31) * His 1 mother likes every man 1 .

Our strategy of generating an inverse scope reading by evaluating the object first and then the subject would lead us to bind the pronoun his to the variable introduced by every man. However, this is considered unacceptable and we would therefore like to avoid doing that in our model. This kind of problem represents a challenge to the fundamental assumptions behind our methodology. Anaphora forces us to evaluate the constituents in linear order, subject first and object last, so that we do not license cataphora from object to subject. Inverse scope forces us to evaluate the constituents in inverse order, object first and subject last, so that the object can take scope over the sentence before the subject does.

In our current setting, this conflict seems impossible to resolve. However, we can find a solution by decomposing the action of a quantified noun phrases into two steps:

1. The quantified noun phrase takes scope over its matrix clause without making the variable anaphorically accessible. The quantified noun phrase is "replaced" by a trace computation.

2. The trace is evaluated, making the variable anaphorically accessible.

This strategy can be summarized by saying that even though a quantifier can move out and in front of a sentence, it is its original position, represented by a trace, which controls its anaphoric behavior.

Our denotations ' and  use the ∃ and ∀ dynamic quantifiers, where ∀ is expressed in terms of ¬ and ∃. The ∃ quantifier itself is defined by the introduce operation.

∃ x. A = introduce ⋆ (λx. A) ∀ x. A = ¬(∃ x. ¬ A)
The introduce operation is interpreted by the box handler as installing an existential handler and introducing the variable into the context. box = . . . . . . , introduce: (λ_k. η (λe. ∃ ≫ x. k x ≪• (x :: e))), . . . . . . We can decompose introduce into two operations, fresh and push, one to wrap an existential quantifier with a fresh variable over the discourse (fresh) and another to add an individual into the context (push). fresh : 1 ↣ ι push : ι ↣ 1

These two operations will replace introduce, which is expressible as their composition, and their interpretations replace the interpretation of introduce in the box handler: box = . . . . . . , fresh: (λ_k. η (λe. ∃ ≫ x. k x ≪• e)), push: (λxk. η (λe. k ⋆ ≪•(x :: e))), . . . . . .

introduce : 1 → (ι → F E⊎{fresh,push} (α)) → F E⊎{fresh,push} (α) introduce = λ_k. fresh ⋆ (λx. push x (λ_. k x))
We can now adjust the dynamic quantifiers so that they only introduce a quantifier over the discourse without modifying the context.

∃ x. A = fresh ⋆ (λx. A) ∀ x. A = ¬(∃ x. ¬ A)

Adding Quantification

217

We can now give a new meaning to the determiners every and a.

, '

: N -• QN P QN P = F {scope} (F E ′ (ι))  = λN. scope (λk. ∀ x. SI ((N ≪• x) ≫= assert!) → k x) (λx. η (trace x)) ' = λN. scope (λk. ∃ x. SI ((N ≪• x) ≫= assert!) ∧ k x) (λx. η (trace x)) trace : ι → F E ′ (ι) trace = λx. push x (λ_. η x)
We split the computations into two layers: an outer layer using the scope effect, where the order will determine the relative scope of quantifiers (using the fresh effect in the ∃ and ∀ quantifiers), and an inner layer using all the other effects in E ′ , where the order will determine the behavior of other phenomena such as anaphora (e.g., the push of the QNP's trace and the get of an anaphoric pronoun). This way, we can have a different order of evaluation in the two layers and get inverse scope readings without risking the violation of crossover constraints.

We could have introduced two layers of computation into all of our NP meanings but this would needlessly create complexity. Instead, only the meanings of quantified noun phrases (abstract type QN P ) will have two layers. We can then plug these meanings into our grammars using one of these two lexical items: - : QN P -• N P - = λQ. Q ≫= (λX. X)

QR : QN P -• (N P -• S) -• S QR = λQK. Q ≫= K
- collapses the two layers of effects so that quantified noun phrases become single-layer computations, just like other NPs. With this lexical item, we recover the original readings that were possible with the single-layer denotations of every  and ' that we had at the beginning of this section.

Furthermore, we can use QR to generate inverse scope (and all the other permutations of quantifiers from 6.4.1). QR evaluates the outer layer of effects before the matrix clause, allowing it to take scope. The computation in the inner layer, which is responsible for adding the quantified variable into the context and making it anaphorically accessible, takes the place of the QNP's trace.

Using QR, we can explain the inverse scope reading of Example 32.

(32) A woman loves every man.

( -• • top 159 ) QR ( ) (λO.  O (' ))
↠ ∀y. man y → (∃x. woman x ∧ love x y)

However, we cannot use the same mechanism to derive the incorrect reading of Example 31.

159 After adding deixis, the type of top became ι → F E (1) → F ∅ (o). However, we will often look at sentences which are not indexical. In such cases, we will overload top to also mean "the top handler without the withSpeaker handler", type F E\{speaker} (1) → F ∅ (o). This means we will not be obliged to provide a referent for the speaker. (34) * He 1 likes every man 1 's mother.

However, there is a configuration that we can construct in our grammar in which a kind of crossover is permitted. If we aim for the reading where there is a dog and it loves every one of its owners (i.e. we raise the QNP a dog), then everything works correctly: we predict that the binding is impossible. However, if we raise the whole object QNP every owner of a dog to get the reading in which there are possibly multiple different dogs, then we will license the cataphoric binding from a dog to it. Even though the raising of the object will not make the dog-owner available as an antecedent to the subject, we will still have evaluated the object QNP's restrictor owner of a dog, which has the effect of introducing a new discourse referent, a dog. If we were to outlaw cases like these, we would need a more robust way of delaying the introduction of discourse referents.

Considering Restrictive Relative Clauses

There is one construction that we have not treated in our grammar and those are restrictive relative clauses. We will sketch out possible ways of dealing with those along with some of the challenges.

  : (N P -• S) -• N -• N
Contrary to supplementary (appositive) relative clauses, which attach to noun phrases and add extra information about their referent, restrictive relative clauses attach to nouns and narrow down the set of individuals under consideration, just like subsective adjectives (e.g. woman, and woman who loves books as book-loving woman).

Restrictive relative clauses let us use the extension of any verb phrase as the extension of a noun: for a given verb phrase P , we can form the noun one who P s. We therefore have an injection from verb phrases to nouns, telling us verb phrases are nouns too. The question now is whether the type of interpretations we use for nouns is large enough to fit the denotations of verb phrases.

N P -• S = N P -• S = F E (ι) → F E (1) N = F E (ι → o)
There are two important issues here. Firstly, the denotations of our sentences are computations that express their truth conditions using side effects. On the other hand, the denotations of our nouns are taken to be computations that produce predicates, pure functions from individuals to propositions. Secondly, the effects in the denotations N P -• S can depend on the individual in N P = F E (ι) whereas the effects in the denotations F E (ι → o) must be independent of the argument individual.

The latter will lead us to trouble if we try fixing the former too naively:

  = λKN. C (λx. N ≫= (λn. K (η x) ≫= (λ_. η (n x))))
Here we add the truth conditions of the relative clause to the noun by including the side effects of the clause in the effects of the noun. However, this only works when the effects of the relative clause are independent of the entity x under consideration, 162 which is rarely the case. For example, assuming that The evaluation of C is blocked because the operation assert (love x m) depends on x. The truth conditions of x P s, where P is a verb phrase, will always depend on x and so this approach will not work. However, our system already has a well-defined way for turning dynamic propositions into simple propositions, and that is the box handler.

  = λKN. C (λx. N ≫= (λn. box (K (η x)) ≫= (λp. η (n x ∧ p))))   = λKN. C (λx. (N ≪• x) ≪∧≫ box (K (η x)))
By wrapping the meaning of the relative clause in a box, its truth conditions (assert and introduce) are contained within the noun's predicate and they do not block the C operator. However, adding the box in the entry for   does have its repercussions. 163 It will lead to the blocking of anaphoric binding from the noun, as in the Example 7.

(7) Every farmer who owns a donkey 1 beats it 1 .

Our entry for   gives the following meaning to the noun farmer who owns a donkey:

  (λx.  ( ) x)  ↠ η (λx. farmer x ∧ (∃y. donkey y ∧ own x y))
The result is a pure computation that is not going to introduce any referents into the discourse (because all of the introduce operations were captured by box) and therefore it is not going to be able to license the anaphoric binding to the pronoun it in Example 7.

We have seen that by not using box evaluation gets stuck because the assert operations that carry the truth conditions of the relative clause are not independent of the argument to which the noun's extension is applied. On the other hand, by using box, the introduce operations that introduce new discourse referents are blocked and cannot license the kind of anaphora that we see in Example 7. We can find the middle ground between the two by only handling assert to get the truth conditions and letting introduce project outside of the noun.

withAssertions : F E⊎{assert} (1) → F E (o) withAssertions = assert: (λpk. p ∧≫ k ⋆), η: (λ_. ⊤)   = λKN. C (λx. (N ≪• x) ≪∧≫ withAssertions (K (η x)))
Now, if we reexamine the meaning of the noun farmer who owns a donkey under the new interpretation of   , we find that the new discourse referent projects outside of the noun and will therefore be able to bind the pronoun in Example 7:   (λx.  ( ) x)  ↠ introduce ⋆ (λy.

η (λx. man x ∧ donkey y ∧ own x y))

However, this solution can be lacking when the dynamic property which is the denotation of the noun introduces new discourse referents itself (e.g. the man who owns a dog).

 (  (λx.  ( ) x) ) ↠ presuppose! (λx. ∃y. man x ∧ dog y ∧ own x y) If we were to accommodate such a presupposition, we would introduce at the global level a new discourse referent satisfying the above condition. However, the binding potential of the NP a dog would have already been wasted by the use of box (or in the case of TTDL, the use of λe. ⊤). This means that we would not be able to account for the binding in Example 36. (36) The man who owns a dog 1 loves it 1 .

Before we address this issue, we turn to another similar problem. We will consider a very similar situation, but instead of introducing a discourse referent, the relative clause will trigger a presupposition where the description of the presupposed individual will contain a variable bound by the relative clause. For example, in the man 1 who loves his 1 dog, the genitive construction his 1 dog is a presupposition trigger but the presupposition cannot project outside of the relative clause because the variable 1 has scope only over the relative clause. If we were to calculate the meaning of the man 1 who loves his 1 dog in the TTDL of [80], we would get the following: the man 1 who loves his 1 dog = λPeϕ. P (sel (λx. raise (AbsentIndividualExc (λy. dog y ∧ poss x y))) e) e ϕ At this point, we would get stuck since the exception cannot propagate outside of the λ-abstraction λx, because x is bound within the exception's message, λy. dog y ∧ poss x y.167 However, in TTDL we can fix this by using the same intermediate accommodation handler as is used in the dynamic existential quantifier to solve the binding problem. 168 In our approach, the handler responsible for intermediate accommodation, maybeAccommodate, is already part of the box handler and so evaluation does not get stuck and the presupposition is accommodated. Nevertheless, to get the intended reading of the noun phrase above, we will have to make the argument to the property anaphorically accessible within the noun:169  = λN. C (λx. box (push x (λ_. N x))) ≫= (λn.

presuppose! n)

We can now use this entry to compute the meaning of the noun phrase the man 1 who loves his 1 dog. When presenting the result, we use the empty and search handlers to filter out the irrelevant branches (looking for the antecedent of his dog in the context and trying to project outside of the relative clause).

search (empty  (  (λx.  (  ) x) ) ) ↠ presuppose! (λx. ∃y. dog y ∧ own x y ∧ man x ∧ love x y) We have solved the problem of the definite description the N who P s where P triggers a presupposition dependent on N . However, there is still the same issue that we encountered at the beginning of this subsection. When we accommodate the presupposition triggered by the definite description the man who loves his dog, we introduce the man as a discourse referent. However, the scope of the quantifier ranging over dogs will be limited to the proposition ∃y. dog y ∧ own x y ∧ man x ∧ love x y. This means that we will not be able to explain the anaphoric binding in Example 37.

Chapter 8. Composing the Effects (37) The man 1 who loves his 1 dog 2 treats it 2 well.

Sketching a Solution -Dynamic Presuppositions

If we want the dynamic effects of definite descriptions to have discourse-wide scope, then we should move their whole evaluation, not just their results, to the global context. We can change the type of presuppose so that we are not signalling the presupposition of static properties but of dynamic ones.

presuppose : (ι → F E * (1)) ↣ ι However, we have to be careful about the effect signature E * used above. From the discussion in Section 8.5, we know that E * cannot include presuppose : (ι → F E * (1)) ↣ ι because then E * is not well-defined. For similar reasons, E * cannot contain scope :

((ι → F E ′ (1)) → F E ′ (1)) ↣ ι, because presuppose ∈ E ′ .
We can dispose of the presuppose effects by evaluating them and accommodating them using introduce and assert should they depend on the argument of the property (e.g. the man who is talking to Peter should presuppose the existence of a salient individual called Peter and the man 1 who is talking to his 1 friend should, when accommodated, introduce two individuals, a man and his friend).

The scope effect can be eliminated either by evaluating it (i.e. projecting it) or by handling it with SI. Handling it would give us narrow scope w.r.t. the presupposition, whereas projecting it would give us wider scope. We find that both are possible: narrow scope in Example 38 and wide scope in Example 39. We will therefore choose narrow scope by default, since in that case we can always derive the wider scope by quantifier raising with QR. (38) The owner of every book ever published by Elsevier must be very rich. (39) Mary sent an email to the representative of every country.

Coming at it from a different angle, we can start looking at the effects that we need to have in E * . Our dynamic properties need to convey truth conditions (assert) and introduce discourse referents (introduce, or rather its parts: fresh and push).

Next we look at what to do with the anaphoric operation get. If we were not to evaluate the get operation at the point where the presupposition is triggered but rather project it as part of the presupposed material and evaluate in the global context (or some other accommodation site), then we would not be able to derive the reading of Example 40. If we were to evaluate x is the sound of their voice in the global context, we could no longer bind the pronoun their to its intended antecedent. On the other hand, we cannot evaluate the get operations without evaluating the introduce operations (which we do not want to do since we want to evaluate them at accommodation-time) because otherwise we would break anaphoric binding within the dynamic proposition being presupposed. For example, in Example 41, we would need to evaluate the introduce operation of the indefinite a car in order for the get operation used by the pronoun to be able to bind to the car. We can deal with this by preserving the get operations in the material being presupposed (so that internal anaphoric binding will work correctly) but making sure that they have access to all the referents available at the point of triggering the presupposition. For this kind of manipulation, we introduce the inTheContext handler, which for any context e and computation X will yield the computation inTheContext e X that, when evaluated, will have access to the material in the context e.

inTheContext : γ → F E⊎{get} (α) → F E⊎{get} (α) inTheContext = λe. get: (λ_k. get ⋆ (λe ′ . k (e + + e ′ )))

Finally, we have the rest of the effects, such as speaker and implicate. We could either evaluate them at the point where the presupposition is triggered or include them into the set of effects E * that is projected with the presupposition. Note that if we include them in E * , then they might get evaluated twice: once when the argument to presuppose is evaluated down to a static property to be used with sel P to search for an existing referent satisfying the definite description, and then, if the referent does not exist, a second time to accommodate the presupposition and evaluate all of its dynamic effects in the global context. If we include these effects into the dynamic property that is given to presuppose as an argument, then these should be idempotent so that repeated evaluation does not interfere with the semantics, or we should take special care of them when doing multiple evaluations. Both speaker and implicate are idempotent, so we are not limited by this factor. However, we still want to keep E * as simple as possible and so we will evaluate these effects at the point where the presupposition is triggered. This means that the effect signature E * in presuppose : (ι → F E * (1)) ↣ ι will be the E DRT effect signature from Chapter 7, though with introduce replaced with fresh and push due to the changes we have made in 8.5.1.

E * = { get : 1 ↣ γ, fresh : 1 ↣ ι, push : ι ↣ 1, assert : o ↣ 1 }
Our intention is to handle or evaluate the effects of the noun in the definite description with the exception of the effects in E * . This means that we want to split the computation of the noun's meaning into two layers: one using the effects in E \E * and another using the effects in E * . We can write a handler for this.170 separateDynamics :

F E⊎E * (α) → F E (F E * (α)) separateDynamics = get: (λxk. get x •≫ (C k)), fresh: (λxk. fresh x •≫ (C k)), push: (λxk. push x •≫ (C k)), asssert: (λxk. assert x •≫ (C k)), η: (λx. η (η x))
We can now finally give an interpretation to the definite article  as well as the other presupposition triggers.

packageProperty : (ι → F E⊎E * (1)) → F E⊎{get} (ι → F E * (1)) packageProperty = λP. get ⋆ (λe.
C (λx. separateDynamics (inTheContext e (maybeAccommodate (SI (P x))))))

Note on Conservativity

An interesting feature of the grammar is that as we added more and more phenomena throughout Sections 8.2, 8.3, 8.4 and 8.5, we rarely modified the interpretations of existing entries. For example, we did not need to turn our interpretations of proper nouns or pronouns into generalized quantifiers when adding quantification, we did not need to change the interpretation of transitive verbs to account for the fact that both subject and object might carry conventional implicatures, etc.

The changes that we did to existing interpretations consisted almost exclusively of inserting handlers for new effects which did not exist in the grammar before. For example, in Section 8.2, we added the useFind and maybeAccommodate handlers for the new presuppose operation into the box combinator and in Section 8.5, we added the SI handler for the new scope operation to the interpretations of tensed verbs. In all those four sections, we also modified the top combinator by composing it with a handler for the newly defined effect. However, we know that if we apply a handler to a computation in which none of the operations being handled occur, then the result will be the same computation (modulo stuck computations). Therefore, we have a strong conservativity result for our incremental grammar. In the grammars developed from Sections 8.1 to 8.5 (Subsection 8.5.1 not included), if an abstract term has an interpretation in one grammar, then it has the same interpretation in every other grammar in which it is derivable (i.e. in every one of its extensions). This is because any extension would only change the interpretation by inserting handlers for effects which are not used in the interpretation and therefore the handlers would make no difference.

Conclusion

We start the conclusion of our thesis by summarizing the results we have obtained (Section 9.1). We proceed chapter by chapter and review the material, highlighting the important contributions. We then examine related work out there and compare it to our approach (Section 9.2). We first speak about the calculus λ itself, considering the alternatives that exist already and explaining in which ways λ is different (9.2.1). Then, we turn to the linguistic analyses that we presented in our dissertation and relate them to the closest analogues in semantics literature (9.2.2). Finally, we review recent work which focuses on combining multiple monads or linguistic effects in a single grammar and see how λ compares to those (9.2.3). We end our thesis bringing up directions in which the work presented here can be extended (Section 9.3).

Summary of Results

In Part I, we have introduced λ , a formal calculus that extends the simply-typed λ-calculus (STLC) with effects and handlers. The definition of λ is given in Chapter 1. λ introduces a new family of types into STLC, the computation types, and new terms, which are built out of computation constructors and destructors. We gave a type system to the calculus which extends that of STLC and a reduction semantics which combines the STLC β and η reductions with definitions of the new function symbols. During the course of the chapter, we maintain two perspectives on the intended meaning of the terms: computations can be seen as programs that interact with a system through a selected set of "system calls" (operations) or they can be seen as algebraic expressions built upon an infinitary algebraic signature.

In Chapter 2, we gave an example of using the λ calculus. Besides familiarizing the reader with the notation and reductions of the calculus, the example served as a preview of the kind of language engineering we would be doing. During the chapter, we developed a compositional semantics for a simple computing language with errors and variables. This let us demonstrate the modularity of using our computation monad, as we could add variables to the language without needing to modify the semantics of the other constructions.

Chapter 9. Conclusion

The main contribution of Part I lies in Chapter 3, in which we developed the metatheory of λ . In Section 3.1, concepts which are primitive in some other languages (closed handlers and the ≫= operator) were defined within λ and their typing rules and reduction rules were derived from those of λ . In Section 3.3, we then connected the calculus to the theory of monads by identifying a monad in the category in which we interpret λ with our denotational semantics. In Section 3.2, we proved subject reduction of λ . This result gives a basic coherence between the type system of λ and the reduction semantics, guaranteeing that types are preserved under reduction. This is complemented by a proof of progress, which states that terms which do not use any of the partial operators and which can no longer be reduced must have a very specific shape.

We followed this with another fundamental property: strong normalization. Its proof was split into two parts: confluence (proved in Section 3.4) and termination (proved in Section 3.5). The proofs of both confluence and termination proceed by similar strategies: prove the property for the calculus without ηreduction by applying a general result and then extend the property to the complete calculus. In the case of confluence, the general result is the confluence of orthogonal Combinatory Reduction Systems [76]. In the case of termination, we rely on two techniques: the termination of the reduction relation of Inductive Data Type Systems that validate the General Schema [19] and Higher-Order Semantic Labelling [55], which lets us use our denotational semantics to label the terms of our calculus so that it validates the General Schema. Andrej Bauer made the analogy that effects and handlers are to delimited continuations what while loops or if-then-else statements are to gotos [15]. Continuations themselves have proven to be a useful tool in natural language semantics [36, 12, 115, 38, 11, 14]. In Chapter 4, we have shown how λ can simulate delimited continuations, namely the shift/reset delimited control operators. We presented a typed call-by-value λ-calculus with shift and reset and have simulated its types and reductions in λ .

In Part II, we have demonstrated the applications of λ to the problem of modelling the meaning of natural language utterances. After having reviewed the basics of formal semantics in Chapter 5, we have shown how computations in λ can be used to give a compositional account of several "non-compositional" linguistic phenomena in Chapter 6. We have described how to introduce computations into a compositional semantics while preserving the meanings assigned by the semantics in Section 6.1. We have then presented analyses of several linguistic phenomena in the framework of λ computations: deixis (Section 6.2), conventional implicature à la Potts (Section 6.3) and quantification à la Montague (Section 6.4). We have then explicitly described the methodology used to find the kinds of analyses that we have presented in Chapter 6 as to encourage researchers to develop other analyses in the framework.

We dedicated Chapter 7 to a particularly complex phenomenon: dynamics. In Sections 7.1 and 7.2, we have shown how a λ analysis of dynamics can be extracted from Discourse Representation Theory. This gave us a way to handle dynamics in λ as well as strengthen the claim that effects and handlers are suitable mechanisms for dealing with natural language. We have also shown how to interpret the λ computations as the dynamic propositions of de Groote's Type-Theoretic Dynamic Logic (TTDL) [38]. In her dissertation [80], Lebedeva extended TTDL with exceptions to treat presuppositions and in Section 7.3, we integrated Lebedeva's analysis of presupposition into our λ analysis of dynamics (we compare our adaptation with the original in the next section, 9.2.2). In Section 7.4, we considered another extension of TTDL, Double Negation TTDL [111] and we have shown why the kind of generalization of denotations done in Double Negation TTDL is not amenable to being analyzed as a side effect in λ .

In Chapter 8, we have supported our claim that using effects and handlers lets us combine distinct phenomena in a single grammar. We have started with the dynamic grammar developed in Chapter 7, repeated in Sections 8.1 and 8.2. We have then extended this grammar with conventional implicatures (8.3), deixis (8.4) and quantification (8.5) with little to no modification of the original semantics. We finished the chapter by sketching out an analysis of restrictive relative clauses and their interactions with presuppositions in Section 8.6.

Comparison with Existing Work

231

Comparison with Existing Work

Calculus

λ can be compared to several existing calculi and implementations of effects and handlers:

• System F (i.e. the polymorphic λ-calculus or the second-order λ-calculus) λ extends the simply-typed λ-calculus with computation types F E (α). Computations are algebraic expressions and as such can be expressed as inductive data types. 174 Inductive data types, along with the sums and products that we add to the calculus in Section 1.5, can be expressed in System F [132].

In λ , a computation of type F E (α) can also be given the type F E⊎E ′ (α), where E ⊎ E ′ is an extension of E. However, in the direct encoding of λ into System F, for every effect signature E ⊎ E ′ that we would like to ascribe to a computation, we would end up with a different term. On the other hand, in λ we can keep using the same term. This lets us give a semantics to lexical items that does not have to change when new effects are introduced into the theory.

• Eff

The Eff language [16] is an ML-like programming language with effects and handlers. Like in ML, effects can be freely used within any expression, without any term encoding (we say that the calculus is direct-style). For this to work correctly, the calculus has a fixed evaluation order, which, following ML, is call-by-value.

We have used Eff in our first explorations of effects and handlers in natural language semantics [89], benefiting from the existing implementation. However, we have found that besides call-by-value, call-by-name evaluation is also common, notably on the boundaries of lexical items (see 6.5.2). Callby-name can be simulated in call-by-value by passing around thunks (functions of type 1 → α for some α). However, in the presence of both call-by-name and call-by-value, we have opted for an indirect presentation of effects using monads which favors neither call-by-value nor call-by-name and that lets us manipulate the order of execution using ≫=.

Finally, we note that Eff is a general-purpose programming language which includes general recursion (let rec) and therefore it is not terminating, contrary to λ .

• λ eff

The λ eff calculus [63] is a call-by-push-value λ-calculus [82] with operations and handlers. Call-bypush-value is special in introducing two kinds of terms: computations and values. The intuition behind the two is that computations do, whereas values are. Two of the crucial things that computations do are to pop values from a stack (that is what abstractions do) and to push values to the stack (that is what applications do). Therefore, applications and abstractions are considered as computations. Furthermore, the function in an application term must be a computation term (which is expected to, among other things, pop a value from the stack), whereas the argument, which is the value to be pushed to the stack, must be a value term. This might make it look like that call-by-push-value is like call-by-value since all the arguments passed to functions are values. However, in true call-by-value, we can use complex expressions as arguments and we expect that the reduction system will evaluate the arguments down to values before passing them to the function. To do this in call-by-push-value, we have to implement this manually by evaluating the argument computation down to a value x and then passing the value x to the function in question (i.e. in λ eff syntax let x ← M in F x). In λ , this amounts to the term M ≫= F , where M : F E (α) and F : α → F E (β). To implement call-by-name, computations can be mapped to values by wrapping them in thunks, which are primitive constructs in call-by-pushvalue (in λ eff syntax F {M }, where M is a computation and the thunk {M } is a value). In λ , the corresponding term is F M , where M : F E (α) and F : F E (α) → F E (β). λ eff presents an intriguing alternative to λ . The call-by-push-value calculus is flexible enough to accommodate both call-by-name and call-by-value. λ-abstractions and operations are both treated as effects, which might make the definition of the C operator, which permutes λ with operations, more intuitive. 175 λ eff also has a well-developed metatheory, developed in [63]: it is both confluent (due to its reduction relation being deterministic) and terminating (thanks to its effect type system).

λ eff served as an inspiration to the design of λ ; notably, λ 's effect system is based on that of λ eff . However, λ diverges from λ eff in that it is a proper extension of the simply-typed λcalculus (STLC): every term, type, typing judgment or reduction in STLC is also a term, type, typing judgment or reduction in λ . For example, the STLC term λx. x is not a λ eff term. Its closest counterparts in λ eff would be either ⊢ ∅ λx. return x : A → F (A), where A is a value type, or

⊢ E λx. x! : U E (C) → C,
where C is a computation type (a function or an effectful computation). On the other hand, in λ , ⊢ λx. x : α → α is a valid term for any α, be it an atomic type such as o, a function type such as ι → o or a computation type such as F E (o).

The fact that λ is an extension of STLC motivates its use for two reasons. First, STLC is the lingua franca of formal semantics. λ already introduces a lot of new notation and the use of effects in natural language semantics is not yet ubiquitous. By basing λ on STLC, we narrow the gap between the common practice of formal semantics and our use of effects and monads, hopefully making the technique more approachable to researchers in the field. Second, the purpose of the calculus is to write down computations that produce logical representations. By having STLC as a subpart of λ , terms of Church's simple theory of types (i.e. formulas of higher-order logic) are already included in our calculus and we can reuse the same notions of λ-abstraction and variables. In λ eff , we would either need to add constructors for logic formulas (i.e. having some logic as an object language over the terms of which the meta language λ eff would calculate) or use call-bypush-value computations in our logical representations.

• Extensible Effects of Kiselyov et al [71] and other implementations of effect systems in pure functional programming languages (Haskell, Idris …)

Our adoption of a free monad and effect handlers was motivated by the paper of Kiselyov, Sabry and Swords on extensible effects [71]. The paper presented a Haskell library for encoding effectful computations, combining computations with diverse effects and interpreting them by composing a series of modular interpreters. The library used a free monad (in the style of [123]): a computation is either a pure value (η in λ ) or a request to perform some kind of effect (an operation in λ ). These requests are then handled by interpreters which behave similarly to effect handlers (the authors of [71] also relate handlers to the technique of "extensible denotational language specifications" published in 1994 by Cartwright and Felleisen [24]). The paper demonstrated that the approach is more flexible when it comes to combining interacting effects than the existing stateof-the-art technique of using monad transformers. A more refined version of the approach was published in [70] and similar implementations of effects and handlers exist also in other pure functional programming languages such as Idris [22].

The extensible effects discipline provides the tools that we would like to use to build a modular semantics of natural language. However, we do not want our formal semantics to depend on the semantics of a large programming language such as Haskell 176 or Idris. We created λ to reap the benefits of extensible effects without incurring the complexity of using a language like Haskell as our meta language. λ extends STLC only with computation types, two constructors (η and operations), two destructors (handlers and -• ) and the C operator. Unlike Haskell, our extension of STLC preserves strong normalization. 175 The extra typing rule for the C construction in λ eff would look like this: 176 The implementations of extensible effects in Haskell make use of a wealth of language extensions which are not even part of the Haskell standard.

Γ ⊢ E M : A → C Γ ⊢ E C M : F (U ∅ (A → C))

The Case of the C Operator

A notable feature which distinguishes λ from all of the above-mentioned calculi is the C operator. The C operator was added relatively late to the λ calculus as a solution to the following problem.

(43) A man 1 walks in the park. He 1 whistles.

In Example 43, the noun phrase a man introduces a quantifier ranging over men that takes scope over its continuation λx. x walks in the park. He whistles. : ι → F E (o). 177 The problem is how to combine an effectful predicate of type ι → F E (o) with a quantifier such as ∃ : (ι → o) → o. The key insight is that the effects of the continuation usually do not depend on the individual being talked about. No matter whether the sentence speaks about Albert, Bill or Charles, the continuation will proceed the same. The continuation will look into the context to retrieve the antecedent x, which is known to satisfy the predicate man and therefore be eligible for use with a masculine pronoun. It will then produce the logical formula walk-in-the-park x ∧ whistle x. The resolution of the anaphoric pronoun does not depend on the particular individual being discussed.

DRT is capable of deriving a meaning for Example 43 without considering which individual the noun phrase a man refers to. DRT does this by calculating with symbolic representations. The noun phrase a man will introduce a discourse referent, a symbolic object distinct from any individual found in the model. Then the evaluation of the discourse continues and the anaphoric pronoun can resolve to this symbolic object. We could do the same in λ . We could state that the ι type is not the type of individuals in the model, but the type of some symbolic objects (discourse referents or variables), and that the type o is not the type of propositions, but the type of logical formulas. Assuming that we had an operation gensym : 1 ↣ ι which could give us fresh variables and that the type of the constructor for formulas of existential quantification would be ∃ : ι → o → o, we could wrap the existential quantifier over an effectful computation P : ι → F E (o) the following way: gensym ⋆ (λx. P x ≫= (λp.

η (∃ x p)))

By changing the meaning of the type ι to be the type of symbolic references, we solve our problem. When we need to evaluate the effects of a continuation of type ι → F E (o), we do not need to know the precise identity of the individual ι. Instead, we apply the continuation to a symbolic object which will stand in for any such individual and then proceed to evaluate the effects of the continuation. This is the approach that we were using at the beginning of the project [89].

However, this approach has several downsides. First, our formal semantics is contaminated by extra complexity due to the management of variables and operations like gensym. Second, there is an extra level of indirection in place. Instead of computing the truth value of a sentence in some model, we compute a formula and then that formula itself can be evaluated in a model. Third, binding in logical formulas is no longer managed by the (meta) calculus. This means that it is easy to gensym a variable that is supposed to occur in the scope of a quantifier and then have that variable accidentally project outside of its scope, leading to the generation of malformed logical formulas.

The C operator presents another solution to this problem. If we know that in a continuation of type ι → F E (o), the effects of the F E (o) do not depend on the ι, we could move them out of the body of the function. This is exactly what the C operator does. 178 With it, we can wrap the existential quantifier over the continuation using the following expression, which we called ∃ ≫ P in 7.3.1:179

∃ •≫ (C P )

The inspiration for the C operator came from Philippe de Groote's work on logical relations and conservativity [39]. Within his work, de Groote makes use of the following mathematical structure: a type transformer T equipped with three operation U, • and C with the following types:

U : α → Tα • : T(α → β) → Tα → Tβ C : (α → Tβ) → T(α → β)
and obeying the following laws:

(U f ) • (U a) = U (f a) C (λx. U (f x)) = U f
If we ignore the C operator for the moment and focus only on the T type transformer, the U and • operations and the first of the two laws, we see that we have a weaker version of an applicative functor. An applicative functor is a functor, which, in our category, is a type transformer such as T, 180 equipped with two operations, pure and ⊛, which have the same types as U and • respectively, and which satisfy the four laws given in 3.3.5. The first of the two laws given above is the homomorphism law 3.8 of applicative functors. We note that all three instances of this structure that are used in the examples of [39] also satisfy the other three applicative functor laws.

We now look at the C operator, whose type is the same as the C operator that we added to λ (with F E corresponding to T). Its behavior is specified only by the second law, which defines the value of C when applied to a pure function (a function of the form λx. U (f x)). Our C also obeys this law by including it as the C η reduction rule, which is part of the definition of C: 181

C (λx. η (f x)) → Cη η (λx. f x) → η η f
Our definition of C also includes the C op reduction rule. This extends the definition of C to computations which use operations. However, our definition of C is not total, as there are well-typed arguments for C which will cause computation to get stuck. This correlates with the C operator in de Groote's work, where certain values of the C operator are left undefined.

It is interesting that the C operator which turned out to be useful in our work originated in another work whose objective was also to capture the way meanings are extended in formal semantics. In our approach, we address conservativity, 182 the subject of de Groote's paper, in two ways. First, we show how to lift a simply-typed semantics into a monadic semantics while preserving the meanings it assigns to sentences in Section 6.1. Then, in Chapter 8, we extend a dynamic grammar with presuppositions (8.2), conventional implicature (8.3), deixis (8.4) and quantification (8.5), and at every step, the only modifications we make to existing entries is to add handlers for new effects, which does not affect the meaning of any of the sentences analyzed before. Furthermore, since for any effect signature E, F E is a type transformer which together with η as U, ≪•≫ as • and C as C has the structure needed in [39], de Groote's technique of logical relations should apply to the kinds of meanings produced by our approach as well. 183

Linguistic Modelling

Most of the linguistic analyses presented in our thesis are translations of existing analyses to the λ framework: 180 Ignoring the arrow-component of the functor. 181 The fact that we can take this law and use it as a definition of the C operator is due to η being a constructor in λ , η-headed expressions are not head-reducible and therefore can be reliably pattern-matched on. 182 Conservativity is understood as the notion that extending the grammar to cover a new phenomenon should not change the meanings which were already correct in the simpler grammar.

183 Modulo the partiality of C.

We use deixis as the first example in Chapter 6. Wanting to give an example of a handler for speaker that appears within a lexical entry, we turned to direct quotations. However, the meanings that we give to sentences such as Example 44 only express part of the meaning. Namely, we capture the fact that Peter claims that Mary kissed him. Nevertheless, the sentence also entails that Peter uttered the sentence "Mary kissed me". Therefore, in our analysis, the sentence in Example 44 would be judged equivalent to the sentence in Example 45. The meaning of direct quotation does not depend only on the meaning of the quoted clause, but on its exact form. Since our system is strictly compositional, 185 we would need to make it so that the meaning of every sentence is the sentence itself. More elaborate treatments of quotation can be found in [47, 109, 119].

(44) Peter said "Mary kissed me".

(45) Peter said "I was kissed by Mary".

• Dynamics

Our treatment of dynamics was presented as a reengineering of DRT and hence it covers DRT as it is presented in Chapter 1 of [64]. It also originated as a reconstruction of de Groote's Type Theoretic Dynamic Logic (TTDL) [38, 80] using monads of effects and handlers [89]. Therefore, it also covers the fragment of TTDL presented in [38] and [80].

Giorgolo and Unger have used the state monad to model DRT-style dynamics [52] and the technique was later refined by Unger [129]. The most challenging aspect in both solutions ends up being the management of accessibility with respect to the scope of quantifiers or logical operators such as negation. In the former [52], the state is a tree data structure with a pointer and the denotations manipulate it by appending children to the tree and moving the pointer up the tree. In the latter [129], the state is a stack of contexts and denotations have to allocate new contexts on the stack and clear them from the stack when the contexts should no longer be accessible. This pattern of encapsulating the dynamic effects of some part of a sentence lends itself very well to the handler abstraction. In our treatment of dynamics, we use an effect handler (box) and avoid the overt manipulation of any tree or stack of contexts; our contexts are just sets discourse referents and propositions.

• Presuppositions

In her thesis [80], Lebedeva gave a compositional account of presupposition projection and accommodation by introducing exceptions and handlers into TTDL. Our use of effects and handlers was strongly influenced by Lebedeva's use of exceptions and so our analysis of presuppositions follows the same strategy. However, we argue that the resumable nature of effects makes them more appropriate for the treatment of presuppositions. We have given a detailed comparison of our approach and Lebedeva's original in 7.3.5, which we summarize here:

-We preserve strong normalization, even though we have exceptions and recursion (in handlers).

-We do not licence cataphoric binding from presupposition triggers because we can resume on presupposition failure without reevaluating the previous parts of discourse.

-We reuse the same mechanism we have used to treat dynamicity, effects and handlers (i.e. the same formal apparatus that projects context updates outside of sentence boundaries is used to project presuppositions outside of downward entailing contexts).

Combining Linguistic Effects

Our work is not the only work aimed at combining different linguistic effects in a single grammar. During our research, several proposals have appeared. Below, we relate them to our approach.

• Monad Transformers [27, 13] Monad transformers map simpler monads into more complex monads with some additional structure. If we want to have a monad with enough structure for, e.g., state, nondeterminism and exceptions, we can take the corresponding monad transformers and apply them, one after another, to some base monad. Monad transformers were evoked as a possible solution to the problem of composing monads by Shan in his first paper on monads for natural language semantics [113]. Since then, they have been used by Charlow in his dissertation [27] and featured in Barker and Bumford's ESSLLI 2015 course [13].

To motivate one of the reasons one might prefer effects and handlers instead of monad transformers, we will look at an example lexical entry from [27]:

pro := λs. {⟨s ⊤ , s⟩}
The monads in use here are the state monad to treat discourse updates and the set monad to treat indefinites. Meanings in the composite monad can depend on some discourse state, they can modify the discourse state and they can propose a set of possible readings. The meaning of pronouns, pro, relies on one of these three capabilities. It makes use of the discourse state s, in which it looks for the salient ("topical") referent, s ⊤ . Then, to have the correct type and fit in with the other definitions, it must also supply the output state and the set of possible readings. The output state will be just the input state s and the set of possible readings will be the singleton set {⟨s ⊤ , s⟩}. This is the case even though the pronoun has no nondeterministic effect, i.e. its structure in the set monad is trivial. We contrast this with the entry for pronouns that we use in λ :  = get ⋆ (λe. η (sel she e))

We use the get operation to access the discourse state e, which corresponds to the λs abstraction in the monad transformer example. Then we use the sel she function to retrieve the salient referent from the state of discourse e, which corresponds to the use of the _ ⊤ operator. Finally, we return this referent as the result using η, which corresponds to packing the referent in a pair with the output state s and then wrapping it in a singleton set. Note that no other effect (such as introduce, which would be the analogue to the set monad structure) is mentioned within the lexical entry. If we were to extend the grammar with new effects, the interpretation of  would stay the same.

On the other hand, if we were to add a new monad to the stack of monad transformers in the former example, then the semantics of pro would need to be lifted.

There is a way to avoid lifting when working with monad transformers. We characterize every monad transformer by some capabilities/operations it gives us and then we write abstract polymorphic terms which can be interpreted in different monads provided that they have enough structure to interpret the capability/operation. This is the method presented in [84, 61] and used in (Haskell) libraries implementing monad transformers [3]. However, formalizing this method already leads us half of the way towards effect and handlers (we write computations using abstract operations and the type of the computation indicates the operations that must be interpreted).

• Setting the Monads Loose [31, 50, 30, 28, 29] During his invited lecture at Barker and Bumford's ESSLLI 2015 course [13, 31], Simon Charlow presented another strategy for combining the different monads. It consists of adding the η and the ≫= of every monad to the lexicon as type shifters. When given a sentence, the grammar then assigns a reading to every possible way of gluing the meanings of the parts of the sentence in a type-sound way. There is therefore no need to define any supermonad to serve as the universal glue since the task of gluing together the pieces from different monads is up to the parser. The same strategy was also adopted by Giorgolo and Asudeh in their ESSLLI 2015 course [50]. They presented fragments of type-logical grammars with different modalities ⋄ i for different monads.

The logic itself contained inference rules which correspond to the monadic primitives (e.g. η is the rule which lets us deduce ⋄A from A). Giorgolo and Asudeh further strengthen the glue available

Chapter 9. Conclusion

to the logic by adding distributivity laws: rules that can commute certain monadic structures (e.g.

⋄ i ⋄ j A → ⋄ j ⋄ i A).
In our thesis, instead of going this road, we build a composite (free) monad. We do so because of two reasons. First, our investigations are motivated by the search for a wide-coverage abstract categorial grammar (ACG) with formal semantics. In ACGs, derivations are expressed in an abstract grammar, which intuitively corresponds to a level of deep syntax. Using a similar approach would force us to introduce semantic types into the level of abstract syntax. Furthermore, the logic which licences derivations would need to be extended to include monadic types (i.e. we would need to add modalities to the implicative fragment of linear logic used in ACGs), which means we would risk losing the existing ACG meta-theory, such as parsing results. Second, the point of using λ is to deal with "non-compositional" phenomena in a compositional setting. If we rearrange the deep syntax so as to facilitate composition, then we could be considered cheating. 186 • Conservativity via Logical Relations [39] In [39], de Groote proves a general conservativity result that guarantees the preservation of predicted meanings under a class of extensions/embeddings, including those that a semanticist might use when introducing a new phenomenon to a grammar. While this gives us a way of porting an existing grammar into a new framework with different types of interpretation, it does not tell us how to add new entries to the ported grammar. As an example, we will take the dynamic grammar from [27], which we featured in the monad transformer example with the following example:

pro := λs. {⟨s ⊤ , s⟩} Suppose we want to introduce conventional implicatures (CI) to this grammar and we do so by embedding the interpretations into a domain in which at-issue meanings are paired with CI contributions. If our embedding function satisfies the preconditions in [39], we will have preserved all of the existing meanings. Now, we want to add non-restrictive relative clauses (NRRCs), which contribute CIs. However, we have to give their meaning in a domain with states, sets and conventional implicatures. Below is the de-sugared semantics that Charlow gives to the NRRC construction [28]:

comma k = λx. λs. {⟨x • p, s ′ ⟩ | ⟨p, s ′ ⟩ ∈ k x s}
The salient part of the entry is that the referent of the appositive is x and the contributed CI is p, the meaning of the relative clause k applied to x. However, we also need to handle the state and so we abstract over s, pass it to k x to get an output state s ′ and then bundle the output state s ′ with our result x • p. Furthermore, there is the set structure, and so we need to take into account the fact that k x s gives us a set with multiple pairs ⟨p, s ′ ⟩ and we need to give our meaning for all of them. The structure of this entry on the set monad level and state monad level is trivial since (under this analysis) NRRCs have no interesting interaction with discourse state or indefiniteness.

As the number of phenomena in the grammar grows, we would like a way to abstract over the nonrelevant parts of the meaning structure. This is something that can be seen in the sugared version of the semantics that Charlow gives to this operator [39]:

comma k = λx. do p ← k x return: x • p
as well as in our lexical entry for the same construction: 187

186 Though when it comes to "non-compositional" phenomena, cheating compositionality might actually be the methodologically sound approach. 187 The entry we see here is simplified from the one in 6.3 to match that of Charlow. This is because in ACGs, we must specify the meaning of the phrase X, who K, in terms of the meanings of X and K, where X is a noun phrase with potentially complex monadic structure and K is a sentence missing such a noun phrase (i.e. a relative clause). Therefore, in the entry in 6.3, we have to evaluate X : F E (ι) down to x : ι and when applying K to x, we have to wrap x in η. In Charlow's approach, it is not the duty of the lexical entries to manage evaluation. Rather, it is the grammar which includes the necessary combinators and type shifters which will evaluate X for us. While the conservativity result of de Groote lets us be confident when porting a grammar to a different type of interpretation, it does not help us when extending it with new entries. It is this problem that is addressed by the techniques presented here and in the works of Simon Charlow. Specifically, in our setting, we do not view the different phenomena in a language as forming a hierarchy in which one extends the other. 188 Instead, it is the case that any lexical entry can use any subset of the phenomena it needs. For example, she is anaphoric but not quantificational, every man is quantificational but not anaphoric, you is neither anaphoric nor quantificational but deictic, your husband is both deictic and presuppositional but not quantificational… • Applicative Abstract Categorial Grammars [68, 69] In Subsection 3.3.5, we spoke about applicative functors. Applicative functors generalize monads since every monad is also an applicative functor but not vice versa. The structure of an applicative gives us two combinators, pure : α → F α and ⊛ : F (α → β) → F α → F β. The intuition behind applicative functors vs monads is that applicatives embody computations with static control flow whereas monads embody computations with dynamic control flow [86].

Comparison with Existing Work

⊛ : F (α → β) → F α → F β =≪ 189 : (α → F β) → F α → F β
When combining computations using ≫=, as in the case of a monad, we can take a computation F α and chain it with a continuation of type α → F β, where the computational structure (i.e. the effects) can vary depending on the value of type α. However, when combining computations using ⊛, as in the case of an applicative, we can only take two computations whose computational structure is already fixed.

Kiselyov argues that since sentence structure is itself also static, applicative functors are a good fit [68]. In Section 6.1, we have seen that we can lift the semantics of a second-order abstract categorial grammar (ACG) into computations using only η and ≪•≫, which constitute the applicative structure of λ . Second-order ACGs are relevant not only because they can be efficiently parsed [65], but also because they are sufficient to encode mildly context-sensitive grammar formalisms such as tree-adjoining grammars [37]. If second-order ACGs are sufficient to model language, then applicative functors could be sufficient to model their meanings. The switch to actually using applicative functors can then be motivated on the basis of the fact that applicatives are composable, unlike monads. 190 Kiselyov's applicative abstract categorial grammars (AACGs) exploit this. In a second-order ACG, terms of the abstract language are formed only by constants and applications. In AACGs, the abstract and object languages are defined to be so-called T-languages, which admit only constants and a binary application operator. Terms of an abstract T-language are then homomorphically mapped to λ-terms that produce terms in an object T-language. As in all ACGs, the function type of the abstract language corresponds to functions. Furthermore, as in our approach, atomic abstract types are mapped to types of the form F(α), where F is some applicative functor and α some object-level type.

The biggest difference between AACGs and our approach is whether we use a composition of applicative functors or a free monad of effects and handlers. The use of applicative functors relies on the assumption that the computational structure (i.e. the control flow) in the semantics is always static. However, even though the structure of sentences is static, we find that the control flow in the semantics can be dynamic. For example, if we consider the noun phrase her car, then the pronoun is a computation of an individual, type F(ι), and the genitive construction is a function over individuals that triggers presuppositions, type ι → F E (ι). To find the referent of this noun phrase, we first have to evaluate the pronoun down to an individual x and then apply the meaning of the genitive construction to this individual, triggering the presupposition that x owns a car. We cannot evaluate the effects of the genitive construction independently of the pronoun since we would not know whose car we are presupposing the existence of and therefore we cannot combine the two meanings using only the ⊛ combinator we have in an applicative functor.

Note that all of the work on combining linguistic effects that was cited in this subsection follows the publication of our initial report [89] from when we were at about a third of the way into working on this dissertation. That is to say that the motivation behind this dissertation was not to challenge the work cited in this subsection, with which it mostly agrees in saying that effects, monads or some other monad-like structure can be used to combine semantic analyses of linguistic phenomena. Nevertheless, we believe that the use of effects and handlers might be interesting to those considering using monad transformers to build a formal semantics. This is especially the case if one is considering to do so in the context of an ACG and wants to therefore use a formal λ-calculus for the semantic calculations. Out of the alternatives mentioned in this subsection, we found the approach of setting monads loose and letting the grammar figure out the semantic glue particularly intriguing as it tries to elegantly sidestep the issue of composing the monads.

Future Work

Future work on λ could be either focused on the calculus itself or its linguistic applications. We finish our thesis with a discussion of both.

Future Work on the Calculus

• Adequacy of Denotational Semantics, Observational Equivalence In Subsection 3.3.1, we have given a denotational semantics to λ . Even though we first gave the reduction semantics, we perceive the denotational semantics as the primary semantics as it assigns to the terms of λ the mathematical objects that we want them to stand for. The reduction semantics can then be seen as a mechanization of computing with these objects. In Chapter 3, we have proven Property 3.3.8, which tells us that our reduction semantics is sound w.r.t. the denotations. However, the converse is not the case (i.e. there are terms which the denotational semantics considers equal but which are not convertible using our reduction rules).

The denotational semantics is useful for reasoning about λ programs. Strengthening the formal link between the denotational semantics and the reduction semantics would therefore be most welcome. The kind of property we are looking for is known as adequacy and it states that if a program and a value have the same denotation, then the program must be able to reduce to that value. For this property to hold, it can be necessary to restrict it only to programs and values of ground types (types which do not "hide" any more computation, such as functions or continuations). An example of such a ground type in λ would be the Boolean type 2. Proving adequacy for terms of type 2 would then yield a result about observational equivalence: if two terms M and N have the same denotation, then they are observationally equivalent, i.e. there is no way to write a Boolean expression in λ whose value differs when switching M for N .

• Commuting Conversions and Extensionality

During the reduction of one of the examples in 7.3.4, to simplify the presentation, we have made use of a reduction rule for passing ≫= (a handler) under case analysis. The formal rule is given below:

Future Work

241

(op i : M i ) i∈I , η: M η (case N c of {inl x → N l (x); inr y → N r (y)}) → case N c of {inl x → (op i : M i ) i∈I , η: M η N l (x); inr y → (op i : M i ) i∈I , η: M η N r (y)}

We note that both the redex and the contractum have the same denotation. On the other hand, if all the M and N terms are normal, then so are both the redex and contractum. Since they are distinct normal terms, this means that the redex and the contractum are not convertible in λ . In other words, this rule is not derivable in our system (even though it is licensed by the denotational semantics).

For completeness' sake, we might like to have rules such as these in λ . They further close the gap between the denotational semantics and the reduction semantics and they can be useful when working with the calculus, as we have seen in the example in 7.3.4. Instead of adding a multitude of commuting conversions such as the one for handlers and sums given above, we can also add extensionality principles, such as the following η-reduction for sums:

case M of {inl x 1 → N [x := inl x 1 ]; inr x 2 → N [x := inr x 2 ]} → N [x := M ]
The commuting conversions that commute over sums can then be derived from this principle [9]. It might also be interesting to seek what would such an extensionality principle look like for computation types. However, the biggest obstacle is that enriching the calculus with new reduction rules puts in jeopardy the established meta-theory (e.g. confluence or termination, whose proofs are usually brittle).

• Conservativity

In the summary of the last chapter, Subsection 8.7.1, we have claimed that modifying a grammar by inserting handlers for effects which are not used anywhere in the grammar has no effect on the semantics. Since this claim plays an important part in motivating the use of λ , it would be desirable to formalize and prove it. 191 • Algebraic Theories of Effects Within the subsections titled "Algebraic Considerations" in Chapters 6 and 7, we studied the equational theories on computations induced by handlers (two computations are considered equal if the handler assigns them the same interpretation). Within these chapters, we looked for general equalities that might become useful and we used those equalities to derive a kind of normal form for the computations. However, the normalization assumes that computations are only sequences of operations terminated by a return value, i.e. they are generated by the grammar below:192 S ::= op M (λx. S) | η M Is it possible to derive similar normal forms for computations built using a larger grammar (e.g. the full λ language)?

In the examples of Chapter 7, we have been making use of these equalities to simplify terms before passing them to a handler. If this practice becomes common, it might be interesting to formalize it.

A good start for both of these problems would be a more thorough investigation of Matija Pretnar's dissertation on the logic and handling of algebraic effects [110], which introduces a calculus of effects, effect theories and handlers.

Future Work on the Linguistic Applications

The plan for future work on the linguistic applications is simple: get more phenomena, more detail, more interactions.

• Low-Hanging Fruit Intensional meanings are parameterized by some possible world. The kind of structure introduced in [18] and [40] is yet another instance of the reader monad pattern. As with deixis, meanings will use a world : 1 ↣ σ operation to access the current world. Modal operators, which will quantify over possible worlds, will then interpret a piece of language while binding the current world to some variable (very much like the way we treated direct quotation, which was binding the speaker to the quotee).

There are also phenomena for which there are already analyses in terms of monads or (delimited) continuations. An example of this is focus, which can be modelled using the pointed powerset monad [113] or using delimited control operators [11]. While such phenomena ought not to be difficult to implement in λ , it might still take some care and empirical work to ensure that the predictions in cases that involve the new phenomenon and the old phenomena turn out the way they should.

• Better Crossover

Approaches to semantics that exploit the analogy to computations and treat anaphora and scopetaking as side effects run into trouble when it comes to inverse scope readings and the crossover constraints. In Subsection 8.5.1, we proposed a solution to the problem which decomposes the effect of a quantificational NP into the scope-taking, which can happen out of linear order, and the anaphora, which must happen in linear order. However, there are still cases in which our grammar can violate the crossover constraints, such as when the contributor of a discourse referent (e.g. the indefinite a dog) hitches a ride in the restrictor of a scope taker (e.g. every owner of a dog), as in Example 35. Crossover issues with inverse scope readings are an old problem [120] and therefore a solution which improves coverage without incurring extra complexity to the rest of the grammar would be of great interest.

• More Dynamics -Double Negation, Modal Subordination and Rhetorical Structure

The treatment of dynamics is easily the most complex application of λ . However, anaphora is much more complicated than what we have seen in this dissertation. Extending it might thus prove to be a good stress test on the level of complexity that is still manageable in λ . Directions for extending dynamics include:

-Double negation, which was studied in Qian's dissertation [111] and which we reviewed in Section 7.4. This is very difficult to apply in our current implementation of dynamics, since negation uses box to encapsulate all of the dynamic effects that take place in its argument. However, to have the law of double negation, we would need to find a way to break this encapsulation, which is tricky since the box handler does encapsulation by throwing away the local structure (i.e. permanently blocking the dynamic contributions).

-Modal subordination, as in Example 46, is another accessibility constraint that was modelled within an extension of TTDL in Qian's thesis [111]. Furthermore, it is a phenomenon that lies at the intersection of two linguistic effects, modality and anaphora, which makes it all the more interesting for a λ analysis.

(46) A wolf 1 might walk in. It 1 would growl.

Future Work

243

-Rhetorical structure informs anaphoric accessibility via the Right Frontier Constraint, as in the famous Example 47 [8].

(47) * John had a great evening last night. He had a great meal. He ate salmon 1 . He devoured lots of cheese. He then won a dancing competition. It 1 was pink.

It remains to be seen whether the handler abstraction, which turned out to be useful to encapsulate the dynamic effects in negation and modelling DRT, would be also useful in analyses of accessibility constraints due to modal subordination or rhetorical structure.

• Champollion -Sentence Meanings as Generalized Quantifiers over Events

In [26], Lucas Champollion presents a semantic fragment in which he combines event semantics with classical phenomena of compositional semantics such as quantification or negation. His work therefore seems to be an ideal starting point for anyone wanting to add events into our λ grammar. However, the types of meanings used within the fragment are quite atypical and therefore it would be interesting to see how many of the theories of the other phenomena developed in this thesis would be compatible with such a semantics.

278

Résumé en français

Les traitements compositionnels de l'intensionalité ou du temps ont tendance à utiliser le λ-calcul simplement typé [18, 40], comme c'est également le cas avec le traitement des anaphores de de Groote [38].

Pour son traitement des présuppositions, Lebedeva utilise une version modifiée du calcul de de Groote qui inclut aussi les exceptions [80]. Il semble clair que pour rendre compte des phénomènes présentés dans les descriptions 1 à 5, il est pertinent de proposer un cadre universel basé sur un langage formel.

Les monades

Notre langage universel est fondé sur le λ-calcul. Grâce au travail très influent de Richard Montague [98], le λ-calcul est un formalisme répandu en sémantique compositionnelle formelle. 194 Beaucoup de systèmes pour la sémantique utilisent le λ-calcul et les autres ont tendance à se traduire en λ-calcul (par exemple la λ-DRT [79] ou le traitement de dynamicité à partir des continuations de de Groote [38]).

Cependant, même si nous avons plusieurs théories qui sont toutes formalisées dans le λ-calcul, cela ne signifie pas nécessairement qu'elles sont compatibles ou que nous savons les combiner. Une théorie de l'intensionalité pourrait déclarer que les phrases sont traduites en termes de type σ → o, le type des fonctions des mondes possibles vers les valeurs de vérité. D'un autre côté, une analyse des expressives suggère que des phrases devraient correspondre à des termes de type o × ϵ, le type des paires composées de valeurs de vérité (le contenu propositionnel) et de marqueurs expressifs (le contenu expressif). Les deux théories seraient compatibles au niveau du calcul utilisé mais pas au niveau des termes. Une fonction traitant des propositions intensionnelles ne seraient pas directement applicables à une proposition expressive.

Pour poursuivre notre recherche d'uniformité et de compatibilité des opérations sémantiques, nous avons examiné les termes et les types utilisés par les traitements sémantiques à partir du λ-calcul et nous avons essayé de trouver une structure sous-jacente commune. Nous remarquons que l'ensemble de ces approches partagent les caractéristiques suivantes : 2. Il existe un processus pouvant transformer des dénotations de l'ancien type dans des dénotations du nouveau type. Dans l'exemple avec les quantificateurs, il s'agit de la fameuse opération de type «type raising». Dans l'exemple avec les intensions, il s'agit du combinateur K qui transforme une valeur de vérité en une fonction constante qui attribue cette valeur de vérité à tous les mondes, (une intension rigide). Dans l'exemple avec des expressifs, c'est la fonction qui couple une proposition avec un marqueur expressif neutre/vide. 4. Enfin, ces approches ont aussi une stratégie de composition des dénotations plus petites en des dénotations plus grandes et de traitement de la complexité ajoutée par les types plus élaborés. Lorsqu'on applique un verbe transitif à un sujet et à un objet quantificationnel, on laisse l'un (souvent le sujet) prendre la portée et ensuite on laisse l'autre prendre la sienne. Lorsque nous appliquons le verbe aux arguments intensionnels, nous passons le monde où nous évaluons la phrase au sujet et à l'objet. Quand on l'applique à des arguments expressifs, on applique le verbe aux référents du sujet et de l'objet et on recueille le contenu expressif des deux.

Ce type de structure est en réalité très commun dans la programmation fonctionnelle et dans la sémantique dénotationnelle des langages de programmation. C'est la structure d'un foncteur applicatif [91]. Les exemples ci-dessus sont également des instances d'une structure plus spéciale appelée une monade [95].

Nous n'entrons pas dans cette section dans les détails de la définition d'une monade que l'on peut retrouver dans ce document, mais nous allons néanmoins en donner un aperçu. Une monade est un triplet (T, η, ≫=) où T est une fonction sur les types (l'expansion des types que nous avons vu dans la section 1), η est une façon de transformer des valeurs simples en valeurs étendues (les fonctions de type raising dans 2) et ≫= nous donne un moyen général de combiner des valeurs de ce type étendu (semblable aux exemples données dans 4). 195 Le triplet doit également satisfaire certaines propriétés algébriques qui garantissent que la composition des fonctions sur des types étendus est associative et que la fonction de type raising sert d'unité pour cet opérateur de composition.

Les analyses discutées ci-dessus sont toutes des exemples de monades. La prévalence des monades dans la sémantique de la langue a déjà été mise en avant par Shan dans [113]. Cependant, le défi consiste à combiner l'utilisation de plusieurs monades en même temps.

Les effets de bord linguistiques

Les monades apparaissent souvent dans la sémantique dénotationnelle des langages de programmation pour tenir compte des notions de calcul communément appelées les effets de bord [95]. Nous pouvons nous baser sur cette correspondance et considérer la structure monadique en langue naturelle comme des effets de bord linguistiques. Cette analogie a été poursuivie par Shan [115, 116] et Kiselyov [67] et est présente dans les travaux récents sur les monades dans la sémantique de la langue naturelle [48, 27]. Cependant, l'idée remonte avant que les monades soient introduites en informatique. Dans leur article de 1977, Hobbs et Rosenschein prennent une perspective computationnelle sur la logique intensionnelle de Montague [98] : les intensions correspondent aux programmes et les extensions correspondent aux valeurs. Un programme peut accéder aux variables globales qui décrivent l'état du monde. 196 Les opérateurs ↑ et ↓, qui traduisent les expressions dénotant les extensions et les expressions dénotant les intensions, correspondent respectivement aux opérateurs quote et eval dans le langage Lisp.

L'idée de traiter les expressions linguistiques comme des actions ou des programmes avec des effets est également pertinente pour la sémantique dynamique, qui traite le sens d'une phrase comme des instructions mettant à jour le «common ground» (ou un autre contexte linguistique).197 La sémantique dynamique et l'anaphore sont parfois classées comme appartenant à la fois à la sémantique et à la pragmatique. C'est également le cas pour d'autres phénomènes que nous traitons comme des effets de bord dans cette thèse : la deixis, la présupposition, l'implicature conventionnelle. La pragmatique étudie la façon dont un langage se situe dans la communauté de ses utilisateurs, c.-à-d. comment il est réellement utilisé par ses locuteurs pour atteindre leurs objectifs. Il ne serait donc pas surprenant que la pragmatique corresponde bien aux effets de bord des langages de programmation, car les effets de bord eux-mêmes concernent la façon dont les programmes peuvent interagir avec le monde de leurs utilisateurs (par exemple, en faisant apparaître des choses sur l'écran ou en récupérant des entrées fournies par l'utilisateur). 195 Cette façon de présenter une monade (un constructeur de type, η et ≫=) est particulière à la programmation fonctionnelle. Notez que cette présentation diffère de celle utilisée dans la théorie des catégories, qui remplace ≫= par une transformation naturelle µ [88].

196 La dépendance à un environnement d'un certain type σ est un effet de bord qui peut être décrit en utilisant la monade «reader». Cette monade transforme le type α vers le type σ → α. Cette transformation de types est exactement la même que celle décrite par les théories d'intensionalisation [18, 40].

Les effets et les handlers

En prenant les différentes structures monadiques de la sémantique de la langue naturelle comme des effets de bord, nous pouvons appliquer des théories qui les combinent pour définir un formalisme capable d'exprimer différents aspects du langage en même temps. Les effets et les handlers sont pour nous un tel cadre théorique. Ici, les programmes sont interprétés comme des séquences d'instructions (ou plus généralement comme des arbres de décision). 198 Les instructions sont des symboles appelés des opérations, qui représentent les différents effets, les différentes façons dont les programmes peuvent interagir avec leur contexte. Dans notre application à la sémantique de la langue naturelle, voici quelques exemples d'opérations qui figurent dans nos définitions, ainsi que leur sémantique :199

• introduce introduit un nouveau référent de discours dans le contexte. C'est l'opération utilisée par des syntagmes nominaux comme l'indéfini a man.

• presuppose P présuppose l'existence d'une entité satisfaisant le prédicat P . Elle est utilisée par des descriptions définies the P et par des noms propres.

• implicate i indique que i est une implicature conventionnelle. Cette opération est utilisée par des constructions appositives telles que John, who is my neighbor.

• speaker demande au contexte l'identité du locuteur. Il est utilisé par le pronom de première personne pour trouver son référent.

Le calcul de la dénotation d'une expression linguistique est décomposé en ces opérations. Lorsque les expressions se combinent pour former des phrases et des discours, ces opérations finissent par être concaténées dans un grand programme qui effectue une série d'interactions avec son contexte. C'est à ce point que les handlers sont utilisés. Un handler est un interpréteur qui donne une définition aux symboles d'opération présents dans un programme. Les handlers peuvent être rendus modulaires200 afin que l'interprète global de toutes les interactions avec le contexte puisse être défini comme la composition de plusieurs petits handlers, chacun traitant un aspect différent du langage (la dynamique, les implicatures, la deixis…).

Lorsque nous utilisons les effets et les handlers, nous commençons par énumérer l'ensemble de toutes les interactions possibles que les programmes (c.-à-d. les expressions linguistiques dans notre application) peuvent avoir avec leurs contextes. Ensuite, nous pouvons interpréter les expressions linguistiques comme des séquences d'instructions. Enfin, nous écrivons des handlers qui mettent en oeuvre ces instructions et produisent une représentation sémantique appropriée. Cette approche suit donc de près le mantra donné par Lewis :

In order to say what a meaning is, we may first ask what a meaning does and then find something that does that. Afin de dire ce que c'est le sens, nous pouvons d'abord demander ce que le sens fait et puis trouver quelque chose qui le fait.

General Semantics, David Lewis [83] Nous pouvons faire remonter les origines des effets et des handlers à deux moments. L'un est le travail de Cartwright et Felleisen sur les Extensible Denotational Language Specifications [24], dans lequel une technique de développement de la sémantique est présentée qui fait que lorsqu'un langage (de programmation) est étendu avec des nouvelles constructions (et des nouveaux effets de bord), les dénotations restent compatibles et peuvent être réutilisées. L'autre précurseur est le travail de Hyland, de Plotkin et de Power sur les effets algébriques [60], une technique catégorique pour étudier les programmes avec des effets de bord, qui fut ensuite étendu par Plotkin et Pretnar pour inclure les handlers [103, 110, 104]. La technique a gagné en popularité ces dernières années (depuis 2012). Elle trouve des applications à la fois dans l'encodage des effets dans les langages de programmation fonctionnels purs [71, 70, 63, 22] et dans la conception des langages de programmation [16, 87, 41, 73, 56]. Notre thèse explore l'applicabilité des effets et des handlers à la sémantique de la langue naturelle.

Résumé des résultats

Après avoir introduit la problématique dans laquelle se situe ces travaux, nous revenons sur une description du contenu du manuscrit.

Dans la partie I, nous introduisons λ , un calcul formel qui étend le λ-calcul simplement typé (STLC) avec des effets et des handlers.

La définition de λ est donnée dans le chapitre 1. λ introduit une nouvelle famille de types dans STLC, les types des calculs, et des nouveaux termes, qui comprennent des constructeurs et des destructeurs des calculs. Nous avons donné un système de types au calcul qui étend celui de STLC et une sémantique de réduction qui combine les réductions de STLC β et η avec les définitions des nouveaux symboles. Dans ce chapitre, nous maintenons deux perspectives sur la signification de ces termes : les calculs peuvent être considérés comme des programmes qui interagissent avec un système à travers un ensemble d'opérations spéciales ou ils peuvent être considérés comme des expressions algébriques construites à partir d'une signature algébrique infinie.

Dans le chapitre 2, nous avons donné un exemple d'utilisation du calcul λ . En plus d'introduire les notations et les réductions du calcul, l'exemple sert d'aperçu du genre d'ingénierie linguistique que nous faisons plus tard dans le manuscrit. Au cours du chapitre, nous développons une sémantique compositionnelle pour un langage informatique simple avec des erreurs et des variables. Ceci nous permet de démontrer la modularité de l'utilisation de notre monade de calcul, car nous pouvons ajouter des variables au langage sans avoir à modifier la sémantique des autres constructions.

La contribution principale de la partie I se trouve dans le chapitre 3, dans lequel nous avons développé la métathéorie de λ . Dans la section 3.1, les concepts qui sont primitifs dans d'autres langues (les handlers clos et l'opérateur ≫=) ont été définis dans λ et leurs règles de typage et de réduction ont été dérivées à partir de celles de λ . Dans la section 3.3, nous avons ensuite relié le calcul à la théorie des monades en identifiant une monade dans la catégorie dans laquelle nous interprétons λ avec notre sémantique dénotationnelle. Dans la section 3.2, nous avons prouvé la préservation des types («subject reduction») dans λ . Ce résultat donne une cohérence entre le système des types de λ et sa sémantique de réduction, garantissant que les types sont conservés par la réduction. Ceci est complété par une preuve de progression, qui indique que les termes qui n'utilisent aucun des opérateurs partiels et qui ne peuvent plus être réduits doivent avoir une forme spécifique.

Nous avons enchaîné avec la preuve d'une autre propriété fondamentale : la normalisation forte. Sa preuve a été divisée en deux parties : confluence (prouvée dans la section 3.4) et terminaison (prouvée dans la section 3.5). Les preuves de confluence et de terminaison procèdent par des stratégies similaires : prouver la propriété pour le calcul sans la η-réduction en appliquant un résultat général, puis étendre la propriété au calcul complet. Dans le cas de la confluence, le résultat général est la confluence des systèmes de réduction combinatoires orthogonaux [76]. Dans le cas de la terminaison, nous nous appuyons sur deux techniques : la terminaison de la relation de réduction dans les systèmes de type de données inductives qui valident le schéma général [19] et l'étiquetage sémantique d'ordre supérieur [55], ce qui nous permet d'utiliser notre sémantique dénotationnelle pour étiqueter les termes de notre calcul afin de valider le schéma général. Andrej Bauer a fait l'analogie dans laquelle les effets et les handlers sont aux continuations délimitées ce que les boucles while ou les constructions if-then-else sont aux instructions du type goto [15]. Les continuations elles-mêmes se sont avérées être un outil efficace dans la sémantique de la langue naturelle [36, 12, 115, 38, 11, 14]. Dans le chapitre 4, nous avons montré comment λ peut simuler des continuations délimitées, à savoir les opérateurs de contrôle délimitée shift/reset. Nous avons présenté un λ-calcul avec appel par valeur et les opérateurs shift et reset et simulé ses types et ses réductions dans λ . Dans la partie II, nous démontrons les applications de λ aux problèmes de modélisation du sens des énoncés de la langue naturelle.

Après avoir examiné les bases de la sémantique formelle dans le chapitre 5, nous avons montré comment les calculs dans λ peuvent être utilisés pour donner une sémantique compositionnelle à plusieurs phénomènes linguistiques "non compositionnels". Dans le chapitre 6, nous avons décrit comment introduire des calculs dans une sémantique compositionnelle tout en préservant les dénotations assignées par la sémantique dans la section 6.1. Nous avons ensuite présenté des analyses de plusieurs phénomènes linguistiques dans λ : la deixis (section 6.2), l'implicature conventionnelle à la Potts (section 6.3) et la quantification à la Montague (section 6.4). Nous avons ensuite décrit explicitement la méthodologie utilisée pour trouver le genre d'analyses que nous avons présentées dans le chapitre 6 afin d'encourager les chercheurs à élaborer d'autres analyses dans le même cadre.

Nous avons consacré le chapitre 7 à un phénomène particulièrement complexe : la dynamique. Dans les sections 7.1 et 7.2, nous avons montré comment une analyse λ de la dynamique peut être extraite à partir de la Discourse Representation Theory. Cela donne un moyen de gérer la dynamique dans λ et renforcer l'idée que les effets et les handlers sont des mécanismes appropriés pour traiter la langue naturelle. Nous avons également montré comment interpréter les calculs λ comme les propositions dynamiques de la Type-Theoretic Dynamic Logic (TTDL) [38]. Dans sa thèse [80], Lebedeva a étendu TTDL avec des exceptions pour traiter les présuppositions et dans la section 7.3, nous avons intégré l'analyse de présuppositions de Lebedeva dans notre analyse λ de la dynamique (nous avons comparé notre adaptation avec l'original dans 7.3.5). Dans la section 7.4, nous avons considéré une autre extension de TTDL pour la double négation [111] et nous avons montré que le type raising des dénotations qui y est utilisé ne peut pas être simulé dans λ .

Dans le chapitre 8, nous montrons comment l'utilisation d'effets et de handlers permet de combiner le traitement de phénomènes différents dans une seule grammaire. Nous avons commencé avec la grammaire dynamique développée dans le chapitre 7, répété dans les sections 8.1 et 8.2. Nous avons ensuite étendu cette grammaire avec les implicatures conventionnelles (8.3), la deixis (8.4) et la quantification (8.5) avec peu ou aucune modification de la sémantique originale. Nous terminons le chapitre en esquissant une analyse des subordonnées restrictives et leurs interactions avec les présuppositions dans la section 8.6.

Résumé

Ces travaux s'intéressent à la modélisation formelle de la sémantique des langues naturelles. Pour cela, nous suivons le principe de compositionalité qui veut que le sens d'une expression complexe soit une fonction du sens de ses parties. Ces fonctions sont généralement formalisées à l'aide du λ-calcul. Cependant, ce principe est remis en cause par certains usages de la langue, comme les pronoms anaphoriques ou les présuppositions. Ceci oblige à soit abandonner la compositionalité, soit modifier les structures du sens. Dans le premier cas, le sens n'est alors plus obtenu par un calcul qui correspond à des fonctions mathématiques, mais par un calcul dépendant du contexte, ce qui le rapproche des langages de programmation qui manipulent leur contexte avec des effets de bord. Dans le deuxième cas, lorsque les structures de sens sont ajustées, les nouveaux sens ont tendance à avoir une structure de monade. Ces dernières sont elles-mêmes largement utilisées en programmation fonctionnelle pour coder des effets de bord, que nous retrouvons à nouveau. Par ailleurs, s'il est souvent possible de proposer le traitement d'un unique phénomène, composer plusieurs traitements s'avère être une tâche complexe. Nos travaux proposent d'utiliser les résultats récents autour des langages de programmation pour parvenir à combiner ces modélisations par les effets de bord.

Pour cela, nous étendons le λ-calcul avec une monade qui implémente les effects et les handlers, une technique récente dans l'étude des effets de bord. Dans la première partie de la thèse, nous démontrons les propriétés fondamentales de ce calcul (préservation de type, confluence et terminaison). Dans la seconde partie, nous montrons comment utiliser le calcul pour le traitement de plusieurs phénomènes linguistiques : deixis, quantification, implicature conventionnelle, anaphore et présupposition. Enfin, nous construisons une unique grammaire qui gère ces phénomènes et leurs interactions.

Mots-clés : sémantique formelle, compositionalité, effets de bord, monades, grammaires catégorielles abstraites, sémantique dynamique.

Abstract

In formal semantics, researchers assign meanings to sentences of a natural language. This work is guided by the principle of compositionality: the meaning of an expression is a function of the meanings of its parts. These functions are often formalized using the λ-calculus. However, there are areas of language which challenge the notion of compositionality, e.g. anaphoric pronouns or presupposition triggers. These force researchers to either abandon compositionality or adjust the structure of meanings. In the first case, meanings are derived by processes that no longer correspond to pure mathematical functions but rather to context-sensitive procedures, much like the functions of a programming language that manipulate their context with side effects. In the second case, when the structure of meanings is adjusted, the new meanings tend to be instances of the same mathematical structure, the monad. Monads themselves being widely used in functional programming to encode side effects, the common theme that emerges in both approaches is the introduction of side effects. Furthermore, different problems in semantics lead to different theories which are challenging to unite. Our thesis claims that by looking at these theories as theories of side effects, we can reuse results from programming language research to combine them.

This thesis extends λ-calculus with a monad of computations. The monad implements effects and handlers, a recent technique in the study of programming language side effects. In the first part of the thesis, we prove some of the fundamental properties of this calculus: subject reduction, confluence and termination. Then in the second part, we demonstrate how to use the calculus to implement treatments of several linguistic phenomena: deixis, quantification, conventional implicature, anaphora and presupposition. In the end, we build a grammar that features all of these phenomena and their interactions.

Keywords: formal semantics, compositionality, side effects, monads, abstract categorial grammars, dynamic semantics.

  variable x, where x is a variable from X constant c, where c is a constant from Σ abstraction λx. M , where x is a variable from X and M is an expression application M N , where M and N are expressions injection η M , where M is an expression operation op M p (λx. M c ), where op is an operator from E, x is a variable from X and M p and M c are expressions handler op 1 : M 1 , . . . , op n : M n , η: M η where op i are operators from E and M i and M η are expressions

Figure 1 . 1 :

 11 Figure 1.1: The typing rules for λ .

Figure 1 . 2 :

 12 Figure 1.2: The typing rule for the handler construction.

Definition 1 . 4 . 1 .

 141 Let M be a term in λ . We define the set of free variables of M , written FV(M ), using the following set of equations:Chapter 1. Definitions FV(λx. M ) = FV(M ) \ {x} FV(M N ) = FV(M ) ∪ FV(N ) FV(x) = {x} FV(c) = ∅ FV(op M p (λx. M c )) = FV(M p ) ∪ (FV(M c ) \ {x})FV(η M ) = FV(M )

Definition 1 . 4 . 3 .

 143 Let M and N be terms and x a variable. We define the capture-avoiding substitution of N for x in M , written as M [x := N ], using the following equations:(λx. M )[x := N ] = λx. M (λy. M )[x := N ] = λy. (M [x := N ]) given that y ̸ = x and y is fresh for N (M K)[x := N ] = (M [x := N ]) (K[x := N ]) x[x := N ] = N y[x := N ] = y given that x ̸ = y c[x := N ] = c (op M p (λx. M c ))[x := N ] = op (M p [x := N ]) (λx. M c ) (op M p (λy. M c ))[x := N ] = op (M p [x := N ]) (λy. M c [x := N ])given that y ̸ = x and y is fresh for N

Definition 1 . 4 . 4 .

 144 Evaluation contexts are terms with a hole (written as []) inside. They are formally defined by the following grammar.C ::= [] | λx. C | C N | M C | op C (λx. M c ) | op M p (λx. C) | η C | op 1 : M 1 , . . . , op n : M n , η: M η C | op 1 : M 1 , . . . , op i : C, . . . , op n : M n , η: M η N | op 1 : M 1 , . . . , op i : M i , . . . , op n : M n , η: C N | -• C | C CDefinition 1.4.5. N is a subterm of M if there exists an evaluation context C such that M = C[N ]. Definition 1.4.6. Let ∼ be a binary relation on the terms of λ . We define the relation [∼], called the context closure of ∼, as the smallest relation that contains ∼ and satisfies the following closure property for any evaluation context C:

Definition 1 . 4 . 7 .Definition 1 . 4 . 8 .Definition 1 . 4 . 9 .Observation 1 . 4 . 10 .

 1471481491410 Let ∼ be a relation. We define the relation ∼ * , called the reflexive-transitive closure of ∼, as the smallest relation that contains ∼ and satisfies the following conditions: • x ∼ * x for any x in the domain of R • if x ∼ * y and y ∼ * z, then x ∼ * z We define a relation called swap on the terms of λ as: • λx. M swap λy. (M [x := y]) given that y / ∈ FV(M ) and that M [x := y] exists • op M p (λx. M c ) swap op M p (λy. M c [x := y]) given that y / ∈ FV(M c ) and that M c [x := y] exists We define the relation of α-equivalence, written as = α , to be [swap] * , i.e. the reflexivetransitive closure of the context closure of the swap relation. = α is an equivalence relation. Proof. swap is a symmetric relation and both context closure and reflexive-transitive closure preserve symmetricity. Reflexivity and transitivity are guaranteed by the reflexive-transitive closure.

unit ⋆ first projection π 1 M

 1 where M is an expression second projection π 2 M where M is an expression left injection inl M where M is an expression right injection inr M where M is an expression case analysis case M of {inl x → N l ; inr y → N r } where M , N l and N r are expressions and x and y are variables from X absurdity case M of { } where M is an expression

product α × β where α and β are types unit 1

 1 sum α + β where α and β are types empty 0

  case X e of {inl x → Y (λu. if u = v then inl x else e u); inr _ → inr ⋆}  = λve. e v  = λXY e. case X e of {inl x → case Y e of {inl y → x/y; inr _ → inr ⋆}; inr _ → inr ⋆}  = λXY e. case Y e of {inl y → inl y; inr _ → X e}  = λXY e. case X e of {inl x → case Y e of {inl y → inl (x + y); inr _ → inr ⋆}; inr _ → inr ⋆}  = λXY e. case X e of {inl x → case Y e of {inl y → inl (x × y); inr _ → inr ⋆}; inr _ → inr ⋆}  = λxe. inl x

-

  then M [x := N ] = N and α = τ . We immediately have Γ ⊢ M [x := N ] : τ from the assumption that Γ ⊢ N : α. If y ̸ = x, then M [x := N ] = x and we get Γ ⊢ M [x := N ] : τ from the assumption that Γ, x : α ⊢ M : τ and the fact that x / ∈ FV(M ).

Definition 3 . 3 . 5 .

 335 Assume given I(c) ∈ α for every constant c : α ∈ Σ. For a well-typed term M with Γ ⊢ M : τ , we define the interpretation of term M as a function M from Γ to τ . The definition proceeds by induction on M : 44 λx. M (e) = λX. ( M (e[x := X]))

Property 3 . 3 . 8 .

 338 Soundness of reduction w.r.t. denotationsWhenever M → N in λ , then M = N .

Law 3 . 3 . 13 .

 3313 op(p, λy. c(y) ≫= f ) ≫= g = op(p, λy. (c(y) ≫= f ) ≫= g) = op(p, λy. c(y) ≫= (λx. (f (x) ≫= g))) = op(p, c) ≫= (λx. f (x) ≫= g) (Left identity for ≫=)

Definition 3 . 4 . 1 .

 341 A reduction relution → on a set A is said to be confluent whenever for each a, b, c ∈ A such that a → b and a → c there is a d ∈ A such that b ↠ d and c ↠ d.

Notation 3 . 4 . 3 .

 343 The intensional λ calculus λ -η is the λ calculus without the η-reduction rule.

3. 4 . Confluence 61 •

 461 the binary symbol @ for function application • the unary symbol λ for function abstraction • a nullary symbol for every constant in the signature Σ • the unary symbol η for the injection operator • a binary symbol op for every op ∈ E • a (n+2)-ary symbol ( op 1 : _, . . . , op n : _, η: _ _) for every sequence op 1 , . . . , op n of distinct symbols from E of length n • the unary symbol -• for the extraction operator • the unary symbol C for the C operator

Chapter 3. Properties Definition 3 . 4 . 11 .

 3411 A CRS is non-overlapping if:

Definition 3 . 4 . 14 .

 3414 Let → 1 and → 2 be two reduction relations on the same set of terms A. → 1 and → 2 commute if for every a, b, c ∈ A such that a ↠ 1 b and a ↠ 2 c, there exists a d ∈ A such that b ↠ 2 d and c ↠ 1 d. Lemma 3.4.15.

•

  If both reductions occurred within a common subterm of a, i.e. a = C[a ′ ], b = C[b ′ ] and c = C[c ′ ] while at the same time a ′ → λ -η b ′ and a ′ → η c ′ , we can use the induction hypothesis for a ′ . This gives us a d ′ such that b ′ ↠ η d ′ and c ′ → = λ -η d ′ and therefore we also have d = C[d ′ ] with b ↠ η d and c → = λ -η d. • If both reductions occurred within non-overlapping subterms of a, i.e. a = C[a 1 , a 2 ], b = C[b ′ , a 2 ] and c = C[a 1 , c ′ ] with a → λ -η b and a → η c: We can take d = C[b ′ , c ′ ] since we have b ↠ η d in one step and c → = λ -η d in one step too. • If the redex in a → λ -η b is the entire term a, but the redex in a → η c is a proper subterm of a: We will solve this by case analysis on the form of a:

  Corollary 3.5.41: λ τ terminates (via Hamana [55]) -Corollary 3.5.42: λ -η terminates (via Lemma 3.5.11) • λ -η + η terminates (3.5.5, Theorem 3.5.46) -because λ -η and η are exchangeable (Lemma 3.5.44)

Definition 3 . 5 . 3 .Definition 3 . 5 . 4 .

 353354 The set of types T (B) contains: • all the types from B • a type α ⇒ β for every α and β in T (B) An IDTS alphabet consists of: • B, a set of base types • X , a family (X τ ) τ ∈T (B) of sets of variables • F, a family (F α1,...,αn,β ) α1,...,αn,β∈T (B) of sets of function symbols • Z, a family (Z α1,...,αn,β ) α1,...,αn,β∈T (B) of sets of metavariables

Definition 3 . 5 . 18 .Definition 3 . 5 . 19 .

 35183519 A constructor c ∈ C β is positive if every base type α = B β occurs only at positive positions in the types of the arguments of c. The base types occurring in positive positions (Pos) and the base types occurring in negative positions (Neg) within a type are defined by the following mutually recursive equations:

Definition 3 . 5 . 26 .

 3526 We say that terms M and N are interreducible, M ⇄ N , if M ↠ N and N ↠ M .

  ⇄ is the quotient of the T presheaf w.r.t. the interreducibility relation. The elements of T /⇄ τ,Γ are interreducibility classes of terms having the type τ in the typing context Γ. We will use the metavariables M and N for these equivalence classes.

N

  c (e[x := X]))) > FE (γ) N c (e[x := d]) which is exactly what we wanted to show. Now we look at the C op rule. C p (λx. op M p (λy. M c )) → op M p (λy. C q (λx. M c )) On the left-hand side, C is applied to Γ ⊢ λx. op M p (λy. M c ) : γ → F E (δ), and on the right-hand side, it is applied to Γ, y : β ⊢ λx. M c : γ → F E (δ) where op : α ↣ β ∈ E. The label p of the left C is the denotation λx. op M p (λy. M c ) while the label q of the right-hand side C is λx. M c . These labels are ordered by the > D(γ→FE (δ)) ordering under which p > q if for all e ∈ Γ and all d ∈ β , we have p(e) > γ→F E (δ) q(e[y := d]). Then to show that p(e) > γ→F E (δ) q(e[y := d]), we will need to show that they are both functions and that for all c ∈ γ , we have p(e)(c) > FE (δ) q(e[y := d])(c). λx. op M p (λy. M c ) (e)(c) = (λX. ( op M p (λy. M c ) (e[x := X])))(c) = op M p (λy. M c ) (e[x := c]) = op( M p (e[x := c]), λY. ( M c (e[x := c, y := Y ]))) λx. M c (e[y := d])(c) = (λX. ( M c (e[y := d, x := X])))(c) = M c (e[y := d, x := c]) = M c (e[x := c, y := d]) We elaborate both of the expressions. The last step in rewriting λx. M c (e[y := d])(c) is due to e[x := X, y := Y ] = e[y := Y, x := X] for distinct variables x and y. From the definition of > F E (δ) (Definition 3.5.30), we get that for all d ∈ β , op( M p (e[x := c]), λY. ( M c (e[x := c, y := Y ]))) > ( M c )(e[x := c, y := d]), which is exactly what we need.

Corollary 3 . 5 . 41 .

 3541 (Termination of λ τ ) The reduction relation induced by the IDTS λ τ is terminating. Proof. By Theorem 3.5.40 and Theorem 3.5.38. Corollary 3.5.42. (Termination of λ -η ) The reduction relation of λ without η-reduction is terminating. Proof. By Corollary 3.5.41 and Lemma 3.5.11.

Definition 3 . 5 . 43 .

 3543 An n-ary evaluation context C n is a λ term in which n disjoint subterms have been replaced with the symbol []. We write C n [M ] for the term in which all of the occurrences of the symbol [] have been replaced with M . Lemma 3.5.44. Exchanging η with λ -η

Figure 4 . 1 :

 41 Figure 4.1: The plan of Chapter 4. The nodes are calculi, solid edges correspond to extensions of calculi, dashed edges correspond to translations of rewriting relations and dotted edges correspond to translations of type systems.

Contents 4 . 1

 41 Introducing Call-by-Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 4.2 Simulating Call-by-Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 4.3 Introducing Control Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 4.4 Simulating shift0 and reset0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 4.5 Turning to shift and reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 4.6 Considering Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 4.7 Other Control Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 86 Chapter 4. Continuations

Corollary 4 . 2 . 5 .

 425 Let M and N be terms of λ v such that M ↠ N . Then we have that M ↠ N in λ .

Definition 4 . 3 . 3 .

 433 A term M reduces to a term N in λ shift0 in one step whenever M and N match one of the patterns below:

Property 4 . 4 . 2 .

 442 Let M and N be terms of λ shift0 . If M → N , then M ↞ ↠ N .

Corollary 4 . 4 . 3 .

 443 Let M and N be terms of λ shift0 . If M ↞ ↠ N in λ shift0 , then M ↞ ↠ N in λ .

4. 5 . 93 Property 4 . 5 . 2 .

 593452 Turning to shift and reset For any λ shift terms M and N , M → N implies M 0 ↠ N 0 .

Corollary 4 . 5 . 3 .Corollary 4 . 5 . 4 .

 453454 For any λ shift terms M and N , M ↠ N implies M 0 ↠ N 0 and M ↞ ↠ N implies M 0 ↞ ↠ N 0 . For any λ shift terms M and N , M ↞ ↠ N implies M 0 ↞ ↠ N 0 in λ .

Definition 4 . 6 . 1 .

 461 A λ shift type is either: • an atomic type ν • a function type α γ -→ β where α, β and γ are other λ shift types

Lemma 4 . 6 . 3 .

 463 Substitution and types in λ shift Whenever we have Γ, x : α | γ ⊢ M : τ and Γ | γ ⊢ V : α, we also get Γ | γ ⊢ M [x := V ] : τ (i.e. we can substitute in M while preserving the type).

Figure 4 . 2 :

 42 Figure 4.2: Typing rules for λ shift .

Property 4 . 6 . 4 .

 464 Subject reduction for λ shift Let us have Γ | γ ⊢ M : τ and M → N . Then also Γ | γ ⊢ N : τ .

Figure 4 . 3 :

 43 Figure 4.3: Proof trees for the proof of Property 4.6.9.

101

 101

  walk, talk, . . .} B T = {John, Mary, Bill, he 0 , he 1 , he 2 , . . .}[START_REF] Lewis | General semantics[END_REF]

110 Chapter 5 .

 1105 Introduction to Formal SemanticsT4 If α ∈ P t/IV , δ ∈ P IV , and α, δ translate to α ′ , δ ′ respectively, then F 4 (α, δ) translates to G 4 (α ′ , δ ′ ),

  a unicorn, F 4 ∀x. man ′ (x) → (∃y. unicorn ′ (y) ∧ love ′ (x, y)), G 4 , F 5 λs. ∃y. unicorn ′ (y) ∧ love ′ (s, y), G 5 F 2 λP. ∃y. unicorn ′ (y) ∧ P (y), G 2 λOs. O (λo. love ′ (s, o)) . . . . . every man, F 0 λP. ∀x. man ′ (x) → P (x), G 0 The second derivation of the sentence gives the object-wide scope reading: . . . . every man loves a unicorn, F 10,0 ∃x. unicorn ′ (x) ∧ (∀y. man ′ (y) → love ′ (y, x)), G 10,0 him 0 , F 4 ∀y. man ′ (y) → love ′ (y, x 0 ), G 4 0 , F 5 λs. love ′ (s, x 0 ), G 5 (λo. love ′ (s, o)) . . . . . every man, F 0 λP. ∀y. man ′ (y) → P (y), G 0 F 2 λP. ∃x. unicorn ′ (x) ∧ P (x), G 2

Definition 5 . 2 . 1 .

 521 A higher-order signature is a triple ⟨A, C, τ ⟩, where A and C are sets and τ is a function from C to linear implicative types I(A) ::= A | I(A) -• I(A). We call the elements of A the atomic types and the elements of C the constants.

114 Chapter 5 .

 1145 Introduction to Formal Semantics J syntax = John M syntax = Mary B syntax = Bill  syntax = λos. s + eats + o  syntax = λos. s + loves + o  syntax = λos. s + finds + o  syntax = λnP. P (every + n)  syntax = λnP. P (the + n)  syntax = λnP. P (a + n)  syntax = man  syntax = woman  syntax = unicorn

116 Chapter 5 .

 1165 Introduction to Formal Semantics J = j M = m B = b  = λos. eat s o  = λos. love s o  = λos. find s o  = λN P. ∀x. N x → P x  = λN P. ∃x. (∀y. N y ↔ x = y) ∧ P x  = λN P. ∃x. N x ∧ P x  = man  = woman  = unicorn The interpretations above follow the ones we have seen in Montague's grammar (Subsection 5.1.2).

( 4 )

 4 It fascinates him.

( 7 )

 7 Every farmer who owns a donkey 1 beats it 1 . ∀x. (farmer x ∧ (∃y. donkey y ∧ own x y)) → beat x y ? ∀xy. (farmer x ∧ donkey y ∧ own x y) → beat x y (8) If a farmer 1 owns a donkey 2 , he 1 beats it 2 . (∃xy. farmer x ∧ donkey y ∧ own x y) → beat x ? y ? ∀xy. (farmer x ∧ donkey y ∧ own x y) → beat x y

  : D(α) → (α → D(β)) → D(β) ≫= 1 : D(1) → (1 → D(1)) → D(1) : D(1) → D(1) → D(1) : Ω → Ω → Ω

125 M,

 125  : N P ,  : N -• N P  : N  : N P -• N P -• S

  M = λP eϕ. P m (m :: e) ϕ  = λP eϕ. P (sel she e) e ϕ  = λN P. ∃ x. N x ∧ P x  = λN P. ∀ x. N x → P x  = λxeϕ. woman x ∧ ϕ e  = λOS. S (λs. O (λoeϕ. love s o ∧ ϕ e))

Contents 6 . 1

 61 Lifting Semantics into Computations . . . . . . . . . . . . . . . . . . . . . . . . . . 127 6.2 Deixis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 6.2.1 Quotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 6.2.2 Algebraic Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 6.3 Conventional Implicature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 6.3.1 Algebraic Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 6.4 Quantification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 6.4.1 Quantifier Ambiguity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 6.4.2 Algebraic Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 6.5 Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 6.5.1 Using Computation Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 6.5.2 Digression: Call-by-Name and Call-by-Value . . . . . . . . . . . . . . . . . . . 144 6.5.3 Choosing an Effect Signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 6.5.4 When (Not) to Use Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

128 Chapter 6 .

 1286 Introducing the Effects J = j M = m  = λos. love s o

Observation 6 . 1 . 3 .

 613 Conservativity of liftingLet ⟨Σ a , Σ o ,v , S⟩ be an ACG where every constant c : τ ∈ Σ a is of at most second-order type (τ = a 1 -• . . . -• a n -• b where all a i and b are atomic types) and let ⟨Σ a , Σ o ,c , S⟩ be the ACG whose lexiconc satisfies the following conditions:

    : S -• N P -• S   : S -• N P -• S We have two lexical items that correspond to the use of  in both direct speech and indirect speech. They differ in surface realization (both in prosody and punctuation) and semantic interpretation. 110   = λCS. say •≫ S ≪•≫ C = λCS. S ≫= (λs. say s •≫ C)   = λCS. S ≫= (λs. say s •≫ (withSpeaker s C))

    : (N P -• S) -• N P -• N P  : N P -• N P -• N P - : N P -• N P

  ≫= (λs. O ≫= (λo. η (love s o)))) ' = λOS. (η • SI) (O ≫= (λo. S ≫= (λs. η (love s o)))) Using the lexical entry, we can now derive the other reading for Example 16: ' ( ) ( ) ↠ η (∃y. woman y ∧ (∀x. man x → love x y)) (16) as well as two more readings for Example 17: ' ( ) ( (- ( -))) ↠ η (∃z. therapist z ∧ (∀x. (∃y. siamese-cat y ∧ own x y) → love x z))

  ( ) ( (- ( -))) ↠ η (∀x. (∃y. siamese-cat y ∧ own x y) → (∃z. therapist z ∧ love x z)) (17) SI QR ( -) (λy. ( ( ) ( (- y)))) ↠ ∃y. siamese-cat y ∧ (∀x. own x y → (∃z. therapist z ∧ love x z)) (17) SI QR ( ) (λz. ( z ( (- ( -))))) ↠ ∃z. therapist z ∧ (∀x. (∃y. siamese-cat y ∧ own x y) → love x z) (17) SI QR ( -) (λy. (QR ( ) (λz. ( z ( (- y)))))) ↠ ∃y. siamese-cat y ∧ (∃z. therapist z ∧ (∀x. own x y → love x z)) (17) SI QR ( ) (λz. (QR ( -) (λy. ( z ( (- y)))))) ↠ ∃z. therapist z ∧ (∃y. siamese-cat y ∧ (∀x. own x y → love x z))

    (  M) J = (λCS. S ≫= (λs. say s •≫ (withSpeaker s C)))   M J ↠ J ≫= (λs. say s •≫ (withSpeaker s   M )) ↠ say j •≫ (withSpeaker j   M ) ↠ η (say j (love m j))

(

  λCS. η (say S •≫ (withSpeaker S (η C)))) •≫   M ≪•≫ J ↠   M ≫= (λc. J ≫= (λs. η (say s •≫ (withSpeaker s (η c))))) ↠   M ≫= (λc. η (say j •≫ (withSpeaker j (η c))))↠ speaker ⋆ (λx. η (say j •≫ (withSpeaker j (η (love m x))))) ↠ speaker ⋆ (λx. η (say j •≫ (η (love m x)))) ↠ speaker ⋆ (λx. η (say j (love m x)))

Figure 6 . 1 :

 61 Figure 6.1: Various trees representing the structure of the term  ( ) ( ).

  CR.LITV: The lexical insertion rule for (transitive) verbs.

Figure 7 . 3 :

 73 Figure 7.3: The lexical insertion construction rules.

choose : 1 ↣ ι 160 Chapter 7 .

 11607 Dynamic Semantics in λ

  get ⋆ (λe. introduce ⋆ (λy. assert (sel e = y) (λ_. η y))) = get ⋆ (λe. introduce ⋆ (λy. assert (sel e = y) (λ_. η (sel e)))) = get ⋆ (λe.η (sel e))

Chapter 7 .

 7 Dynamic Semantics in λ

Figure 7 . 5 :

 75 Figure 7.5: CR.PN: The construction rule for proper nouns.

  the universe of the main DRS: new discourse referent u Introduce into the condition set of the main DRS: new condition α(u)  : P N -• N P P N = ι → o N P = F E (ι)

S 2 =

 2   ( ( M))  ↠ get (λe. introduce ⋆ (λy. assert (Mercedes y) (λ_. assert (own (sel e) y) (λ_. η ⋆)))) Dynamic propositions of type F E DRT (1) are conjoined by chaining their computations. By chaining the two computations, we get a meaning for the whole discourse in Example 20. not S 1 . S 2 = (¬ S 1 ) ≫= (λ_. S 2 ) ↠ presuppose Jones (λx. assert (¬(∃y. Porsche y ∧ own x y)) (λ_. get (λe.introduce ⋆ (λy. assert (Mercedes y) (λ_.

Chapter 7 .

 7 Dynamic Semantics in λ top not S 1 . S 2 = box (accommodate not S 1 . S 2 ) ↠ box ( introduce ⋆ (λx. assert (Jones x) (λ_. assert (¬(∃y. Porsche y ∧ own x y)) (λ_. get (λe. introduce ⋆ (λy. assert (Mercedes y) (λ_. assert (own (sel e) y) (λ_. η ⋆))))))) ) ↠ get ⋆ (λe. η (∃x. Jones x ∧ ¬(∃y. Porsche y ∧ own x y) ∧ (∃y. Mercedes y ∧ own(sel(e ′ ), y))))

  presuppose (λy. children y x) (λy. η (man x ∧ angry x ∧ ¬(frightened y))) + η (∃x. man x ∧ angry x ∧ ∃y. children y x ∧ ¬(frightened y)) + η (∃x. man x ∧ angry x ∧ ¬(∃y. children y x ∧ frightened y))) ≫= (λa. assert! (¬a)) ↠ 139 ((∃ ≫ x. presuppose (λy. children y x) (λy. η (man x ∧ angry x ∧ ¬(frightened y)))) ≫= (λa. assert! (¬a))) + ( η (∃x. man x ∧ angry x ∧ ∃y. children y x ∧ ¬(frightened y)) ≫= (λa. assert! (¬a))) + ( η (∃x. man x ∧ angry x ∧ ¬(∃y. children y x ∧ frightened y)) ≫= (λa. assert! (¬a))) ↠ ((∃ ≫ x. presuppose (λy. children y x) (λy. η (man x ∧ angry x ∧ ¬(frightened y)))) ≫= (λa. assert! (¬a))) + (assert! (¬(∃x. man x ∧ angry x ∧ ∃y. children y x ∧ ¬(frightened y)))) + (assert! (¬(∃x. man x ∧ angry x ∧ ¬(∃y. children y x ∧ frightened y)))) = ((∃ ≫ x. presuppose (λy. children y x) (λy. η (man x ∧ angry x ∧ ¬(frightened y)))) ≫= (λa. assert! (¬a))) + (assert! (∀xy. (man x ∧ angry x ∧ children y x) → frightened y))

η

  (man x ∧ angry x ∧ ¬(frightened y)))) ≫= (λa. assert! (¬a))) + (assert! (∀xy. (man x ∧ angry x ∧ children y x) → frightened y)) + (assert! (∀x. (man x ∧ angry x) → (∃y. children y x ∧ frightened y)))) ↠ ((∃ ≫ x. presuppose (λy. children y x) (λy. η (man x ∧ angry x ∧ ¬(frightened y)))) ≫= (λa. assert! (¬a))); (assert! (∀xy. (man x ∧ angry x ∧ children y x) → frightened y)); (assert! (∀x. (man x ∧ angry x) → (∃y. children y x ∧ frightened y))) ↠ assert! (∀xy. (man x ∧ angry x ∧ children y x) → frightened y)

Definition 7 . 3 . 3 .Definition 7 . 3 . 4 .Notation 7 . 3 . 5 .Lemma 7 . 3 . 6 .

 733734735736 less and for every x ∈ β , c(x) is ⊥-less (op : α ↣ β ∈ E) For Γ ⊢ M ; N : τ , the interpretation M ; N is defined as the following function from Γ to τ :M ; N (e) = { M (e), if M (e) is ⊥-less N (e), otherwiseWe now have a denotational semantics for M ; N . We can use this denotational semantics to produce a reduction semantics for the construction. We define a binary reduction relation R ; on the terms of λ . We write → ; for its context closure. 141• (M ; N ) R ; M if for every Γ and τ such that Γ ⊢ M ; N : τ and for every e ∈ Γ , M (e) is ⊥-less• (M ; N ) R ; N iffor every Γ and τ such that Γ ⊢ M ; N : τ and for every e ∈ Γ , M (e) is not ⊥-less Adding the → ; reduction relation into the reduction relation → of λ preserves subject reduction (Property 3.2.2) since M ; N : α always reduces to either M : α or N : α. It also preserves the soundness of our denotational semantics (Property 3.3.8) because soundness relies on two properties: the compositionality of the denotational semantics, which we preserve, and the fact that the individual reduction rules preserve denotations, which the → ; rule does by definition. The new construction and its reduction rule also preserve confluence and termination, as we will show below, and therefore they also preserve strong normalization. The λ ; calculus is the λ calculus with the M ; N construction and its reduction rule, → ; . Termination of λ ; The reduction relation → of λ ; is terminating. 141 The notion of evaluation context being expanded to include C ::= C; M | M ; C. • b = M and N

5 .Lemma 7 . 3 . 9 .

 5739 If the redex in both a → ; b and a → ; c is the entire term a, then b = c and their common reduct is d = b = c. If b and c were different, i.e. M ; N → ; M and at the same time M ; N → ; N , then M (e) would have to be simultaneously both ⊥-less and not ⊥-less for every e, which is a contradiction. The reduction relation → λ of λ commutes with → ; .

( 27 )

 27 * He 1 loves John's 1 car.

  , ,  : N P  : N -• N P , , P, M : N , ,  : N P -• N P -• S -- : S -• S , -, - : S -• S -• S _._ : D -• S -• D  : D

⊤

  , ⊥ : o ¬ : o → o (_ ∧ _), (_ → _), (_ ∨ _) : o → o → o ∃, ∀ : (ι → o) → o _ = _ : ι → ι → o man,woman, Porsche, Mercedes : ι → o love, own, fascinate : ι → ι → o nil : γ _ ::

3 . 1

 31 and which we repeat here. box : F E⊎E DRT (1) → F E⊎{get} (o) box = λA. ( get: (λ_k. η (λe. get ⋆ (λe ′ . k (e + + e ′ ) ≪• e))), introduce: (λ_k. η (λe. ∃ ≫ x. k x ≪• (x :: e))), assert: (λpk. η (λe. p ∧≫ (k ⋆ ≪•(p :: e)))), η:

8. 4 .

 4 Adding Deixis 213  : N P   : S -• N P -• S   : S -• N P -• S To give a meaning to reported speech, we will introduce into the object signature the predicate say: say : ι → o → o Finally, we extend the lexicon, giving definitions to the new lexical items.  = speaker! ⋆   = λCS. (say •≫ S ≪•≫ (box C)) ≫= assert! = λCS. S ≫= (λs. (box C) ≫= (λc. assert! (say s c)))   = λCS. S ≫= (λs. (top s C) ≫= (λc. assert! (say s c))) top : ι → F E⊎E DRT ⊎{presuppose,amb,implicate,introduce i ,speaker} (1) → F E (o) top := λs. top • withSpeaker s withSpeaker : ι → F {speaker:1↣ι}⊎E (α) → F E (α) withSpeaker = λs. speaker: (λ_k. k s)



  = λN. scope! (λk. ∀ x. SI ((N ≪• x) ≫= assert!) → k x) ' = λN. scope! (λk. ∃ x. SI ((N ≪• x) ≫= assert!) ∧ k x) - = λY. Y ≫= (λy. η (λx. own x y)) SI : F E⊎{scope} (1) → F E (1) SI = scope: (λck. c k) top := λs. top s • SI

   := λOS. SI (  O S)  := λOS. SI (  O S)   := λCS. SI (   C S)   := λCS. SI (   C S)

( 33 )

 33 * He 1 likes every man 1 .

( 35 )

 35 * It 1 loves every owner of a dog 1 .

Chapter 8 .

 8 λx.  M x = λx. assert! (love x m), the meaning of man who loves Mary becomes: 220 Composing the Effects   (λx.  M x)  ↠ C (λx. assert (love x m) (λ_. η (man x)))

( 40 )

 40 Everyone 1 hates the sound of their 1 voice.(41) John met the woman who stole a car 1 by hacking into its 1 computer.

Contents 9 . 1

 91 Summary of Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 9.2 Comparison with Existing Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 9.2.1 Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 9.2.2 Linguistic Modelling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 9.2.3 Combining Linguistic Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 9.3 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 9.3.1 Future Work on the Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 9.3.2 Future Work on the Linguistic Applications . . . . . . . . . . . . . . . . . . . 242

  239  k = λx. k x ≫= (λp. implicate p (λ_. η x))

( 35 )

 35 * It 1 loves every owner of a dog 1 .

1 .

 1 Les types de certaines dénotations sont élargies. Par exemple, lorsqu'il s'agit de quantificateurs, le type des dénotations des syntagmes nominaux va de ι (des individus) à (ι → o) → o (des quantificateurs généralisés sur les individus) ; dans la sémantique intensionnelle, le type des dénotations des phrases va de o (des valeurs de vérité) à σ → o (des fonctions des mondes possibles vers des valeurs de vérité, c.-à-d. des ensembles de mondes possibles) ; et avec les expressives, le type des dénotations des phrases va de o à o × ϵ (des valeurs de vérité associées à des marqueurs expressifs).

3 .

 3 Puis il y a d'autres termes de type étendu qui ne peuvent pas être obtenus en utilisant la fonction de type raising évoqué ci-dessus ; ce sont ceux pour lequel nous avons élargi le type. Les syntagmes nominaux quantificationnel tels que everyone ne sont pas les résultats d'un type raising sur un terme de type d'individu. Les propositions intensionnelles telles que Hespherus is Phosphorus ont des extensions qui varient d'un monde à l'autre. Les expressives tel que le diminutif Wolfie indiquent un individu et portent également un marqueur expressif qui transmet l'attitude du locuteur envers le référent.

  Figure 1.3: Example of applying the C operator to a term.

	1.4. Reduction Rules									15
	M =		. . . . . .	. . . . λ .			C M =	. . . . . .	. . . . op 1 (M 1 ) .
		. . . . . .	. . op 1 (M 1 ) .		. . . . . .	. . op 1 (M 1 ) .			. . . . λ . .	. . op 2 (M 2 ) . . .
	. .	. . A 1	. . op 2 (M 2 ) . . . A 2 . .	.	. . B 1	. . op 2 (M 2 ) . . . . . B 2	.	A 1	B 1	A 2	. . . . λ . .	B 2

2.1 Introducing Our Running Example

. . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 2.2 Adding Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.2.1 Raising the Type of exp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.2.2 Refactoring with Monads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.2.3 Interpreting Expressions as Computations . . . . . . . . . . . . . . . . . . . . 30 2.2.4 Handling Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 2.2.5 Examples with Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.3 Enriching the Context with Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 33 2.3.1 Example with Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 2.3.2 Treating Variables without Computations . . . . . . . . . . . . . . . . . . . . 36 2.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

  [START_REF] Charlow | Conventional implicature as a scope phenomenon[END_REF]

  will start by showing what is a functor and in what way do our computation types form one.

	Definition 3.3.15. A functor is a homomorphic mapping from one category to another. A functor F from a category a C to a category D consists of:

Definition 3.4.5. The metaterms of

  is an n-ary function symbol and t 1 ,…,t n are metaterms, then F (t 1 , . . . , t n ) is a metaterm • if M is an n-ary metavariable and t 1 ,…,t n are metaterms, then M (t 1 , . . . , t n ) is a

	a CRS are given inductively:
	• variables are metaterms
	• if t is a metaterm and x a variable, then [x]t is a metaterm called abstraction
	• if F

metaterm Definition 3.4.6. The terms of

  a CRS are its metaterms which do not contain any metavariables.To finish the formal introduction of CRSs, we give the definition of a CRS reduction rule.

Definition 3.4.7. A CRS reduction rule is

  a pair of metaterms s → t such that:• s and t are both closed, i.e. all variables are bound using the [_]_ abstraction binder • s is of the form F (t 1 , . . . , t n )• all the metavariables that occur in t also occur in s• any metavariable M that occurs in s only occurs in the form M (x 1 , . . . , x k ), where x i

are pairwise distinct variables Definition 3.4.8. A Combinatory Reduction System (CRS) is

	reduction rules.	a pair of a CRS alphabet and a set of CRS

  αn,β and t 1 ,…,t n are metaterms of types α 1 , . . . , α n , respectively, then F (t 1 , . . . , t Definition 3.5.6. The terms of an IDTS are its metaterms which do not contain any metavariables.The definition of an IDTS rewrite rule is almost identical to the one for CRS reduction rules. The only difference is the extra condition stating that the redex and contractum must have identical types. An IDTS rewrite rule is a pair of metaterms s → t such that:• s and t are both closed, i.e. all variables are bound using the [_]_ abstraction binder • s is of the form F (t 1 , . . . , t n )

	Definition 3.5.7.

n ) is a metaterm of type β • if M is a metavariable from Z α1,...,

αn,β and t 1 ,…,t n are metaterms of types α 1 , . . . , α n , respectively, then M (t 1 , . . . , t n ) is a metaterm of type β

6.7. Type soundness for λ shift

  is a valid evaluation context Definition 4.6.6. A λ shift term is stuck when it is not a value and it cannot reduce to any other λ shift term.

	Property 4.

  is a ζ or an ζ according as to whether the first word in ζ takes a or an S4[START_REF] Liang | Monad transformers and modular interpreters[END_REF] If α ∈ P t/IV[START_REF] Lillibridge | Exceptions are strictly more powerful than call/cc[END_REF] and δ ∈ P IV , then F 4 (α, δ) ∈ P t , where F 4 (α, δ) = αδ ′ and δ ′ is the result of replacing the first verb in δ by its third-person singular present.S5 If δ ∈ P IV /T86 and β ∈ P T , then F 5 (δ, β) ∈ P IV , where F 5 (δ, β) = δβ if β does not have the form he n , and F 5 (δ, he n ) = δ him n .S14 If α ∈ P T and ϕ ∈ P t , then F 10,n (α, ϕ) ∈ P t , where either:• α does not have the form he k , and F 10,n (α, ϕ) comes from ϕ by replacing the first occurrence of he n or him n by α and all other occurrences of he n or him

n by he/she/it or him/her/it respectively, according to whether the first noun in α is masculine/feminine/neuter, or • α = he k , and F 10,n (α, ϕ) comes from ϕ by replacing all occurrences of he n or him n by he k or him k

  ).

	. . . . every man loves a unicorn, F 4 . . . . . . .
	. . every man, F 0 . . .		. . love a unicorn, F 5 . . . . . . .
	.	.	. . love	. . a unicorn, F 2 . . .
				. . unicorn

Definition 5.3.1. A Discourse Representation Structure (DRS)

  K is a pair ⟨U, C⟩, where U , the universe, is a set of discourse referents and C is a set of DRS conditions.

DRS conditions consist of:

• atomic conditions P x 1 . . . x n , where P is an n-ary relation symbol and

x 1 , …, x n are discourse referents • ¬K, where K is a DRS • K 1 ∨ K 2 , where K 1 and K 2 are DRSs • K 1 ⇒ K 2 ,

where K 1 and K 2 are DRSs Notation 5.3.2. A DRS ⟨{x 1 , . . . , x n }, {c 1 , .

  Having reduced the noun phrase a Porsche, we are now led to evaluate the noun Porsche itself. It yields the predicate Porsche. At this point, the algorithm presented in

			x y
		Jones x . . . . N(y) . . .			x y Jones x Porsche y
		. . Porsche			. . . . . .	. . . . S.
	.	. . . . . . . . x	. . . . S.	. . VP ′ . . .	→ CR.LIN	.	. . x	. . . . . .	. . VP ′ . . . . . VP .	=	x y Jones x Porsche y [x owns y]	→ CR.LITV	x y Jones x Porsche y own x y
			. . . . . .	. . VP .				. . V . . .	. . y
			. . V . . .	. . y		.	. . owns
		.	. . owns

Corollary 7.3.10. Confluence of λ

  Corollary of Lemma 7.3.8, Lemma 7.3.9 and the Lemma of Hindley-Rosen (Lemma 3.4.15).

	7.3. Presuppositions	193
	; is strongly normalizing, i.e. there are no infinite reduction chains in λ Proof. Theorem 7.3.11. Strong normalization of λ λ ; originating in a λ ; term M terminate in the same term, the normal form of M . ; and all maximal reduction chains
	Proof. Corollary of Lemma 7.3.6 and Corollary 7.3.10.
	;	is confluent.

;

The reduction relation of λ

While in the present, we can only infer that they might be dating, by accommodating the presupposition, we can infer that sometime in the past, they must have been dating.

Frege's compositionality principle states that the meanings of complex expressions should be determined by (i.e. be functions of) the meanings of its constituents. If complex meanings are to be seen as functions of other meanings, it makes sense to use a calculus of functions, i.e. the λ-calculus.

In a similar way that monads can be turned into monad transformers (monad morphisms) and then composed[START_REF] Shan | Monads for natural language semantics[END_REF][START_REF] Wu | Transformers, handlers in disguise[END_REF].

Since the banana brackets can contain an arbitrary number of operator clauses, we adopt the syntax of named parameters/records used in languages such as Ruby, Python or JavaScript.

[START_REF] Barendregt | The lambda calculus: its syntax and semantics[END_REF] This is very reminiscent of the idea behind Paul Blain Levy's call-by-push-value calculus[START_REF] Blain | Call-by-push-value: A subsuming paradigm[END_REF], which treats abstracting over a variable as an effectful operation of popping a value from a stack. Using call-by-push-value could prove to be a rewarding way to refine our approach.

Throughout this manuscript, we will be using the term computation to mean values of type F E (α). Programs written in λ are simply called terms and their normal forms are called values. To break it down, in λ , terms evaluate to values, some of which can be computations (those of an F type).

The two types α and β are to be seen as the operation's input and output types, respectively.

In general, the same operation symbol can be used with different input and output types, in computations whose types are indexed by different effect signatures.

Our use of the word cluster is synonymous with the mathematical term family. We will be using the term cluster for families of computations passed to operations and handlers.

The f in E f stands for forwarded effects, since it refers to effects that the handler will not interpret but instead forward to some other interpreter. The notation comes from a similar rule in the λ eff calculus[START_REF] Kammar | Handlers in action[END_REF].

Violating this assumption will yield terms which get stuck during evaluation (we will see the partial reduction rules in Section 1.4). Sam Lindley presented a refined type system for a similar calculus to track the use of variables[START_REF] Lindley | Algebraic effects and effect handlers for idioms and arrows[END_REF]. A similar refinement should be possible in our case as well but it would obscure the already dense type notation.

[START_REF] Beaver | Presupposition[END_REF] The other direction, typed F E (α → β) → (α → F E (β)), is already possible without introducing a special operator since F E is a functor (as we will see in Subsection 3.3.4).

Congruence means that equivalent inputs are mapped to equivalent outputs.

From now on, this notation will be used for capture-resolving substitution only.

Here, y is a bound variable and we can simply assume that it is different from x and proceed…

…whereas here, y is a free variable and therefore, we have to examine whether it is different from x or not.

= 1 + 1

Chapter 1. DefinitionsΓ ⊢ M : α Γ ⊢ N : β [×] Γ ⊢ ⟨M, N ⟩ : α × β Γ ⊢ ⋆ : 1 [⋆] Γ ⊢ M : α × β [π 1 ] Γ ⊢ π 1 M : α Γ ⊢ M : α × β [π 2 ] Γ ⊢ π 2 M : β Γ ⊢ M : α [inl] Γ ⊢ inl M : α + β Γ ⊢ M : β [inr] Γ ⊢ inr M : α + β Γ ⊢ M : α + β Γ, x : α ⊢ N l : γ Γ, y : β ⊢ N r : γ [case] Γ ⊢ case M of {inl x → N l ; inr y → N r } : γ

The type and effect signature metavariables that appear in the types are bound by the typing constraints of the terms on the right-hand side.

This is not a part of the core calculus as this is only sound when the type of the handler is of the shape F E (γ) → F E ′ (γ) (i.e. when the handler preserves the type γ of values returned by the computation).

The example we will treat might be too simple to actually justify using our calculus. However, it will allow us to see λ in action.

The type N is the type of natural numbers. Since our examples will deal with numbers, we will treat natural numbers as terms of our calculus that have the type N. Their syntax and equational theory are both standard so we will not repeat it here.

Feeding it into ≫= or applying a handler to it are the two most common ways we will be using computations.

This rule will be formally introduced in Subsection 3.1.2. It says that whenever we have (η x) ≫= k, we can reduce it to k x.

Chapter 3. PropertiesFrom the above derivation, we can extract Γ, x : τ 1 ⊢ M ′ : τ 1 → τ 2 . However, since x is fresh for M ′ , we can strengthen this to Γ ⊢ M ′ : τ 1 → τ 2 , which is what we wanted to prove.• M → η N We have M = (op i : M i ) i∈I , η: M η (η M ′ ), N = M η M ′ , τ = F E ′ (δ)and the following typing derivation for M :Γ ⊢ M η : γ → F E ′ (δ) Γ ⊢ M ′ : γ Γ ⊢ η M ′ : F E (γ) … [ ] Γ ⊢ (op i : M i ) i∈I , η: M η (η M ′ ) : F E ′ (δ)From the inferred typing judgments for M η and M ′ , we can build the typing derivation for M η M ′ .Γ ⊢ M η : γ → F E ′ (δ) Γ ⊢ M ′ : γ [app] Γ ⊢ M η M ′ : F E ′ (δ) • M → op N We have M = (op i : M i ) i∈I , η: M η (op j M p (λx. M c )), N = M j M p (λx. (op i : M i ) i∈I , η: M η M c ) and τ = F E ′ (δ). Γ ⊢ M j : α j → (β j → F E ′ (δ)) → F E ′ (δ) Γ ⊢ M p : α j Γ, x : β j ⊢ M c : F E (γ) op j : α j ↣ β j ∈ E [op] Γ ⊢ op j M p (λx. M c ) : F E (γ)… [ ] Γ ⊢ (op i : M i ) i∈I , η: M η (op j M p (λx. M c )) : F E ′ (δ)

Constants are assumed to be reduced away by some external rule. In our case, this will be the application of an ACG lexicon (5.2).

Note that this disjoint union operator ⊔ is different from the ⊎ one from Chapter 1. A⊔B is defined as {(x, 0) | x ∈ A}∪{(x, 1) | x ∈ B}.

In the definition, we make use of (op i : M i ) i∈I , η: Mη (e) and C . This notation is introduced right after this definition.

The plus is a coproduct, which in the case of our category of sets corresponds to disjoint union. We will work with coproducts using a similar syntax to the one that we have given to sums in 1.5.

Note that with this translation, op tp (λx. tc) does not contain λx. tc as a subterm. This is the same as in λ , where the notion of evaluation context (see 1.4) does not identify λx. tc, but rather tc, as a subterm of op tp (λx. tc). This becomes important in our discussion of confluence since it makes it impossible to make the λ disappear by something like η-reduction.

More precisely, if a is a subterm of b in λ then the CRS version of a is a subterm of the CRS version of b. In the other direction, whenever a is a variable or a function-headed term which is a subterm of b in the CRS version of λ , then the corresponding a in λ is a subterm of the corresponding b.

This is not so much a fortunate conincidence but rather a deliberate choice in the design of the calculus. For example, it is one of the reasons why, in λ , η x is not decomposed as an application of the built-in function η to x, but is treated as a special form.

We know that β does not overlap any of the other rules. Neither does it overlap itself since its left-hand side does not have an application subexpression.

This also holds for λ with sums and products since their rules are left-linear and do not overlap with the λ rules.

In the sequel, we will ignore the η-reduction and use IDTSs to prove the termination of λ without η-reduction, λ -η .

Note that throughout this section, we will make a distinction between two notions of "basic" types: atomic types and base types. Atomic types are the basic types of λ . Base types are the basic types of IDTSs. In our particular IDTS, the base types consist of all the types of λ , i.e. the atomic types, the λ function types α → β and the computation types. This means that, from the point of view of the IDTS, λ function types and computation types are just another base type.

In fact, the actual Theorem in[START_REF] Blanqui | Termination and confluence of higher-order rewrite systems[END_REF] states that the system is strongly normalizing. However, by strongly normalizing they mean that every term is computable, i.e. that there is no infinite reduction chain.

These β rules and application operators are different from the ones already in our IDTS. ap is defined for the α → β function type from λ whereas @ serves the α ⇒ β type of IDTS.

Theorem 3.5.12 is proven using Tait's method of computability predicates[START_REF] William | Intensional interpretations of functionals of finite type i[END_REF]. The term computable closure comes from the fact that the admissible right-hand sides are the metavariables of the left-hand side closed on operations that preserve computability.

When we extend a context, we usually extend it with a pair of a variable name and a type, e.g. Γ, x : τ . However, the theory of binding algebras uses Bruijn levels[START_REF] Govert | Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the church-rosser theorem[END_REF], where the names of variables in a context are always integers from 1 to some n. Extending a context x 1 : α 1 , . . . , xn : αn with a type τ then yields a context x 1 : α 1 , . . . , xn : αn, x n+1 : τ .

Natural transformation is the name for an arrow between two functors (presheaves). In our particular setting, naturality boils down to Aγ being a function of (ΣA)γ for every γ.

Same as the CRS valuations introduced in 3.4.1, but typed.

Homomorphisms between Σ-algebras are defined in the same way as homomorphisms for first-order algebras. The term algebra T Σ V is called an initial algebra because we can find a (unique) homomorphism from T Σ V to any other algebra A that works by interpreting terms from T Σ V using the operations of A.

In Subsection 3.5.3, we said that the ordering ≥ F is induced by the form of the rewrite rules. Actually, we are free to define ≥ F ourselves as long as it validates the assumptions and the General Schema.

This result can be extended to λ with sums and products. The pair construction ⟨-, -⟩ and the injections inl and inr will be the constructors for α × β and α + β, respectively, with α < B α × β, β < B α × β, α < B α + β and β < B α + β. All of the rules defining case analysis and projections π 1 and π 2 satisfy the General Schema.

Rules like η can delete metavariables (n = 0 for the metavariable Mη), while others, like , can copy them (n = 2 for the variable M j )

The case of D = [] is not considered, because it is covered by the case where the contractum of the first reduction containts the redex of the second reduction.

Proof. The lack of infinite reduction chains is due to termination of λ (Theorem 3.5.46) and the fact that all maximal reduction chains lead to the same term is entailed by confluence of λ (Theorem 3.4.18).

We have not defined the . interpretation operator for contexts. Contexts are simply terms with a [] inside and so we just extend the . interpretation of terms with the clause [] = [].

This analogy originates with Andrej Bauer who says that effects and handlers are to delimited continuations what while loops or if-then-else statements are to gotos[START_REF] Bauer | Lambda the ultimate -programming with algebraic effects and handlers[END_REF].

This need for explicit weakening of computation types could be eliminated by using actual polymorphic types.

x : α ∈ Γ [var] Γ | γ ⊢ x : α Γ, x : α | γ ⊢ M : β [abs] Γ | δ ⊢ λx. M : α γ -→ β Γ | γ ⊢ M : α γ -→ β Γ | γ ⊢ N : α [app] Γ | γ ⊢ M N : β

The idea behind Eω is that shift0 should be polymorphic in δ. However, we do not have polymorphism in λ , so in this particular case, we will assume we have sufficiently many distinct instances of shift0 covering the different types at which we want to shift.

This means that the calculus can be further extended with other effects whose effect signature would be E.

Γ, x : τ 1 | δ ⊢ M ′ : τ 2 [abs] Γ | γ ⊢ λx. M ′ : τ 1 δ -→ τ 2By induction hypothesis, we get that Γ , x : τ 1 ⊢ M ′ : F E δ τ 2 and by definition, we haveλx. M ′ = η (λx. M ′ ) and τ 1 δ -→ τ 2 = τ 1 → F E δ ( τ 2 ). Let us prove its type. Γ , x : τ 1 ⊢ M ′ : F E δ ( τ 2 ) [abs] Γ ⊢ λx. M ′ : τ 1 → F E δ ( τ 2 ) [app] Γ ⊢ η (λx. M ′ ) : F E γ ( τ 1 → F E δ ( τ 2 )) 3. M = M 1 M 2 Γ | γ ⊢ M 1 : τ ′ γ -→ τ Γ | γ ⊢ M 2 : τ ′ [app] Γ | γ ⊢ M 1 M 2 : τ By induction hypothesis, we get Γ ⊢ M 1 : F E γ ( τ ′ → F E γ ( τ )) and Γ ⊢ M 2 : F E γ ( τ ′ ).By definition, we also haveM 1 M 2 = M 1 ≫= (λm. M 2 ≫= (λn. m n)).We can then construct the type derivation in 4.3a.4. M = reset M ′ Γ | τ ⊢ M ′ : τ [reset] Γ | γ ⊢ reset M ′ : τBy induction hypothesis, we get Γ ⊢ M ′ : F E τ ( τ ), and by definition we have reset M ′ = ( shift0: (λck. c k) M ′ ).E τ = {shift0 : (δ → F E ( τ )) → F E ( τ ) ↣ δ} δ ⊎ E Γ ⊢ λck. c k : ((δ → F E ( τ )) → F E ( τ )) → (δ → F E ( τ )) → F E ( τ ) Γ ⊢ M ′ : F E τ ( τ ) [ ] Γ ⊢ shift0: (λck. c k) M ′ : F E τ [ ] Γ ⊢ ( shift0: (λck. c k) M ′ ) : F E γ ( τ ) 5. M = shift M ′ Γ | γ ⊢ M ′ : (τ δ -→ γ) γ -→ γ [shift] Γ | γ ⊢ shift M ′ : τ The induction hypothesis gives us Γ ⊢ M ′ : F E γ (( τ → F E δ ( γ )) → F E γ ( γ )).We also have shift M ′ = M ′ ≫= (λm. shift0! (λk. shift0: (λck. c k) (m ( • k)))). In Figure4.3b, we construct the appropriate typing derivation for this term.

Chapter 4. ContinuationsΓ ⊢ M 1 : F E γ ( τ ′ → F E γ ( τ )) Γ , m : τ ′ → F E γ ( τ ) ⊢ M 2 : F E γ ( τ ′ ) Γ , m : τ ′ → F E γ ( τ ), n : τ ′ ⊢ m : τ ′ → F E γ ( τ ) Γ , m : τ ′ → F E γ ( τ ), n : τ ′ ⊢ n : τ ′ [app] Γ , m : τ ′ → F E γ ( τ ), n : τ ′ ⊢ m n : F E γ ( τ ) [abs] Γ , m : τ ′ → F E γ ( τ ) ⊢ λn. m n : τ ′ → F E γ ( τ ) [≫=] Γ , m : τ ′ → F E γ ( τ ) ⊢ M 2 ≫= (λn. m n) : F E γ ( τ ) [abs] Γ ⊢ λm. M 2 ≫= (λn. m n) : ( τ ′ → F E γ ( τ )) → F E γ ( τ ) [≫=] Γ ⊢ M 1 ≫= (λm. M 2 ≫= (λn. m n)) : F E γ ( τ ) (a)The case for M = M1 M2. NB: m is assumed to be fresh in M2 (and therefore M2 ), allowing us to get Γ , m :τ ′ → FE γ ( τ ) ⊢ M2 : FE γ ( τ ′ ) from Γ ⊢ M2 : FE γ ( τ ′ ). Γ ⊢ M ′ : FE γ (( τ → FE δ ( γ )) → FE γ ( γ )) Γ ⊢ shift0: (λck. c k) : FE γ ( γ ) → FE( γ ) Γ , m : ( τ → FE δ ( γ )) → FE γ ( γ ) ⊢ m : ( τ → FE δ ( γ )) → FE γ ( γ ) Γ ⊢ : FE( γ ) → FE δ ( γ ) Γ , k : τ → FE( γ ) ⊢ k : τ → FE( γ ) [•] Γ , k : τ → FE( γ ) ⊢ • k : τ → FE δ ( γ ) [app] Γ , m : ( τ → FE δ ( γ )) → FE γ ( γ ), k : τ → FE( γ ) ⊢ m ( • k) : FE γ ( γ ) [app] Γ , m : ( τ → FE δ ( γ )) → FE γ ( γ ), k : τ → FE( γ ) ⊢ shift0: (λck. c k) (m ( • k)) : FE( γ )[abs] Γ , m : ( τ → FE δ ( γ )) → FE γ ( γ ) ⊢ λk. shift0: (λck. c k) (m ( • k)) : ( τ → FE( γ )) → FE( γ ) [op!]

This is due to the fact Γ ⊢ Σ M : α entails that all the variables from the domain of Γ occur free exactly once in M .

This is the notation of Church's simple type theory. The types o and ι correspond to Montague's types t and e respectively. In the rest of the manuscript, we will stick to Church's notation.

It is because the action of a lexicon _ = ⟨F, G⟩ on types is defined as the unique homomorphic extension of F .

The only difference being that we used (_ → _) in the abstract types instead of (_ -• _).

We can also think of this as extending the existential quantification from the first sentence to cover the second sentence.

In[START_REF] Montague | The proper treatment of quantification in ordinary english[END_REF], Montague's grammar includes the similar construction farmer such that he owns a donkey (rules F 3,n in S3).

In our formalization of DRT, we do not admit constants. Instead of having a constant j for Jones, we have a unary relation Jones which is satisfied only by Jones (or only by people whose name is "Jones"). The consequence of this is that in DRT, we can only refer to individuals via discourse referents, which must be introduced in the universe of some DRS.

Accessibility will be formally defined in a coming subsection.

There exist varieties of DRT that are more complex and might include, e.g., modal operators. There, it might be necessary to translate to some other logic.

The definitions below differ slightly from those of Lebedeva[START_REF] Lebedeva | Expression de la dynamique du discours à l'aide de continuations[END_REF]. Instead of updating the context with available individuals, Lebedeva updates the context with facts added to the common ground. Instead of using individuals (type ι), Lebedeva uses dynamic individuals (type γ → ι).

This result is analogous to Barker's Simulation Theorem for the Continuation Schema in[START_REF] Barker | Continuations and the nature of quantification[END_REF]. As in Barker's theorem, this result holds not only for lift L and lift R but to liftings that arbitrarily permute the evaluation order of their arguments.

The semantics of quotations hides many more complexities[START_REF] Shan | The character of quotation[END_REF] and whether quotations shift the interpretations of indexical expressions is under debate. We limit ourselves to using said as an example of how a lexical entry that shifts indexicals would look like in λ .

For a formalization of the use of metavariables, see 3.4.1 or[START_REF] Klop | Combinatory reduction systems: introduction and survey[END_REF].

We could also just as well choose S = o but we want to be consistent with the other treatments we have shown so far and the ones we will see later.

In that case, we would need to have scope : ((ι → F E (o)) → o) ↣ ι ∈ E. This is problematic since E, which contains scope, is then recursive.

This is very much like the situation we have seen towards the end of Chapter 4. The SI handler is our reset. We can only pass the type check if we use shift/reset (Section 4.6). We encode shift as shift0 by using a reset (in our case SI) inside the argument to shift0 (in our case scope), as in Section 4.5.

Though the same applies to the lexical entry for the indefinite article a as well.

We saw quantifier raising in Section 5.1. It is the rule F 10,n from clause S14, or rather its semantic counter part G 10,n in T14.

The overgenerating case is due to a variable escaping its scope. However, such a term with a free occurrence of a variable would not be a well-typed closed term and so such a derivation does not exist in our grammar.

Actually, it can displace any kind of N P effect, including dynamics, and so it can be used, e.g., to implement a kind of cataphora. This will turn out to be a bug, not a feature, because of crossover constraints[START_REF] Shan | Explaining crossover and superiority as left-to-right evaluation[END_REF], to be treated in Subsection 8.5.1.

The construction rules presented in[64] also include gender features, which are necessary for correct anaphora resolution. We will omit them from the rules as we will not be studying anaphora resolution in this work.

The latter is not present in[64]. Instead, [x loves y] is treated as an irreducible condition.

Since we ignore gender, we can think of α as the third-person singular pronoun.

If we were to care about gender markers, the input of this operation would be the gender marker/predicate, much like in the example of the select operator proposed in 6.5.3.

In the case of dynamics, it might be just anaphora, but more generally it might also be indexicality, quantification, conventional implicature…

For example when contexts are lists of individuals ordered by saliency and adding the same individual multiple times increases their saliency.

A projection line is a path in the immediate-subordination tree from a sub-DRS to the root DRS[START_REF] Van Der Sandt | Presupposition projection as anaphora resolution[END_REF]. See the definition of immediate subordination in 5.3.3.

The type of presuppose! is (ι → o) → F E⊎{presuppose} (ι). However, find relies not only on presuppose, but also on get. In most contexts, both are available and so the two are interchangeable.

The same technique is applied in the TTDL of[START_REF] Lebedeva | Expression de la dynamique du discours à l'aide de continuations[END_REF].

We also replace all uses of box with box, i.e. the one in dynamic negation.

If we wanted to retrieve all admissible readings, we could write a handler that would use the M ; N construction to build a list containing all the non-stuck solutions.

The non-terminating λ assumed a global effect signature E and used computation types F (α) which all shared the effect signature E (i.e. every F (α) was implicitly F E (α)). This was problematic because one could use the type F (α) somewhere in the type of one of the operations in E. This created a loop where E explicitly referenced F (α) which implicitly referenced E and it is this loop which is exploited by Lillibridge's encoding of recursive types. This no longer works in the version of λ presented in this manuscript since the type F E (α) now has to explicitly mention E and if E contains F E (α), then it leads to an infinite type. This was sufficient to make Lillibridge's encoding impossible since we have proven λ terminating in 3.5.

The function in question is the iacc handler for intermediate accommodation from Definition 6.29. This handler is part of the definition of the dynamic existential quantifier, which is the only operator using which new variables are introduced.

Not only for dynamicity and presuppositions, but also for quantification, conventional implicature and deixis.

An involution is a function which is its own inverse, i.e. g(g(x)) = x.

We have not covered the interplay of quantification and dynamics, which TTDL studies as well. This will be the subject of Chapter 8.

Note though that in Chapter 6, we had S = F E (o) and after the shift to dynamic semantics in Chapter 7, we switched to S = F E (1).

In Chapter 7, we presented a simplified account of DRT that omitted gender features. We add them back in a limited form to make the examples more comprehensible.

The equation follows from a single reduction using the op.≫= rule (Property 3.1.4).

Shown in[5], but, as far as we can tell, not from a corpus.

A more involved treatment of quotation would use anaphora to look into the context for the situation in which the original sentence was produced and evaluate the sentence in that context.

We already have a lexical entry for the indefinite article from our theory of dynamics. We include another one, which will turn out to be equivalent in most situations, to parallel the one we had in Section 6.4.

When studying presuppositions, we introduced entries for genitive constructions with relational nouns that had the syntactic type N P -• N P . Those correspond to referring expressions such as X's children or X's best friend. The lexical entry - :

as in every owner of a car. We have two ways to dispense with this: having the quantifier embedded within

The difference being that ' projects to the box which contains the nearest scope island marker SI, whereas  project to the nearest box.

We have seen that the box handler corresponds to the boundary of a DRS. We note that DRT does not instruct us to wrap the relative clause in a DRS and we can therefore expect our theory to diverge w.r.t. accessibility.

Below, we use the interpretation of nouns introduced in 8.6.1. However, we could draw similar conclusions for the interpretation of nouns used in the rest of this chapter.

 165 Terminology due to [

[START_REF] Lebedeva | Expression de la dynamique du discours à l'aide de continuations[END_REF].166 This is equivalent to the use of the box handler in our approach.

This kind of stuck term is very similar to the C (λx. presuppose (λy. dog y ∧ poss x y) (λy. Mc(y))) in λ .

The iacc handler that we mentioned in 7.3.5, defined in[START_REF] Lebedeva | Expression de la dynamique du discours à l'aide de continuations[END_REF], Definition 6.29.

In the presentation of TTDL in Lebedeva's thesis[START_REF] Lebedeva | Expression de la dynamique du discours à l'aide de continuations[END_REF], adding the condition man x to the context suffices to make x accessible. In our setting, we make a distinction between adding a fact to the common ground using assert versus introducing a new discourse referent for discussion using push or introduce (this lets us give a (partial) account of crossover constraints).

This amounts to reordering all of the operations in a computation so that the ones in E \ E * go before those in E * . This is not always possible since some of the operations from E \ E * might depend on the results of some of the operations in E * . We can therefore expect the handler to make use of C, our partial operator for messing around with evaluation and functional dependencies.

An inductive type is a recursive type with positive constructors. In 3.5.3, we have seen that a computation type F E (α) has positive constructors η and op for every op ∈ E.

In our presentation of dynamic semantics, where S = F E (1), the type of the continuation would be ι → F E (1).

If we are mistaken and the effects do depend on the bound variable, then computation gets stuck (instead of producing a malformed logical formula).

The type of ∃ is (ι → o) → o and the type of P is ι → F E (o).

We could imagine adding a rule allowing us to permute the order of certain operations, as long as the result of one is not bound in the input to the other. However, we would lose confluence of our calculus at that point.

There are exceptions, such as our treatment of presuppositions, which extends our treatment of dynamics.

=≪ is ≫= with its arguments reversed.

However, the applicative structure that one gets by composing two monad transformers is not necessarily the same as the one that is obtained by composing the corresponding applicative functors.

This might be one of the useful applications of adequacy of our denotational semantics. We can prove that new_op: M N has the same denotation as N , provided that new_op does not occur in the denotation of N . By using adequacy, we could translate the equality of denotations into a reduction in the reduction semantics.

This grammar only allows for computations which always execute the same sequence of operations, irrespective of any of the their outputs. In Lindley's λ flow calculus[START_REF] Lindley | Algebraic effects and effect handlers for idioms and arrows[END_REF], such computations would be called arrow computations[START_REF] Hughes | Generalising monads to arrows[END_REF].

Dans le présent, on peut déduire que les deux sont peut-être en train de sortir ensemble (grâce à l'auxiliaire modal might), mais avec la présupposition, on peut déduire que dans le passé, ils ont dû sortir ensemble.

Il est généralement motivé par le principe de compositionnalité de Frege qui dit que le sens d'une expression complexe doit être déterminé par le sens de ses constituants (c.-à-d. être une fonction de). Si un sens complexe est une fonction d'autres sens, il est logique d'utiliser un calcul sur les fonctions, comme le λ-calcul.

L'utilisation des monades pour encoder des effets dynamiques (l'anaphore) remonte à 2009 et aux travaux de Giorgolo et Unger[START_REF] Giorgolo | Coreference without discourse referents: a nonrepresentational drt-like discourse semantics[END_REF][START_REF] Unger | Dynamic semantics as monadic computation[END_REF].

Plus précisément, nous interprétons des programmes dans une monade libre[START_REF] Swierstra | Data types à la carte[END_REF].

Les opérations ne sont que des symboles et n'ont donc pas un sens inhérent.

De la même manière que les monades peuvent être transformées en «monad transformers» («monad morphisms») puis composées[START_REF] Shan | Monads for natural language semantics[END_REF][START_REF] Wu | Transformers, handlers in disguise[END_REF].

Acknowledgments

Sums and Products

When studying semantics, one of the verifiable predictions that we can make is whether the contents of one utterance entail the contents of another. This issue already preoccupied Aristotle, who addressed the problem in his study of syllogisms. Using his theory, Aristotle could systematically predict that the contents of Example 2 entail the contents of Example 3, i.e. "if (2), then (3)" is a valid argument.

(2) Every man is mortal. Socrates is a man.

(3) Socrates is mortal. For the object pronoun we do the same, introducing the discourse referent v and the condition v = x. Finally, all that is left is to translate the transitive verb into a binary relation and we get the final DRS representation.

Let us now look at the formulation of the construction rules, starting with CR.ID in Figure 7.1. [START_REF] Swierstra | Data types à la carte[END_REF] The triggering configuration describes the rule's redex (and part of its context). In the case of CR.ID, the rule for indefinite descriptions, the redex is a noun phrase of the form a(n) N . The actual triggering configuration also includes the node dominating the NP as well. This is for reasons of evaluation order: "A reducible condition γ must be reduced by applying the appropriate rule to its highest trig- gering configuration, i.e. that triggering configuration τ such that the highest node of τ dominates the highest node of any other triggering configuration that γ contains."

From Discourse to Logic [64] (Section 1.1.4, page 87 in the Student Edition)

In this rule, the extra piece of context in the triggering configuration makes it so that the application of the rule to the subject dominates the application of the same rule to the object and therefore fixes evaluation order: first subject, then object.

The rule then has its contractum, which is given on the last line (Substitute in γ). In this case, the contractum is the discourse referent u. The rule also has two important side effects. First, the discourse referent u is introduced into the DRS that contains this condition. Second, the condition [N ](u) is added to the conditions of that same DRS. The notation [N ](u) means that we copy the whole syntactic structure of N (i.e. the whole program for computing the meaning of the noun) and once its meaning (a predicate) is computed, we apply it to the discourse referent u.

The rule for pronouns, CR.PRO in Figure 7.2, is very similar. It introduces a new kind of operation, in which the NP being evaluated is asking its context for a suitable anaphoric referent.

We will leave the rule for proper nouns until Section 7.3 and give the two lexical insertion rules for nouns and transitive verbs [START_REF] Gendler | Compositionality[END_REF] -Figures 7.3a and 7.3b, respectively.

The system from [64] described above can be presented in a manner reminiscent of operational semantics of programming languages.

The terms of this language are DRSs which contain as conditions syntactic trees with discourse referents. The values in this language are discourse referents and plain DRSs (DRSs whose conditions are formulas). We will define evaluation contexts C. These should reflect the fact the construction algorithm of DRT permits reduction in any of the conditions within a DRS. We can now compute the denotation of Example 22. The meaning of Example 22 is equal to - S 1 S 2 =

, where S 1 is the antecedent and S 2 is the consequent. We start with the denotation of the consequent, S 2 : his car is cheap.

↠ get ⋆ (λe. presuppose (λz. car z ∧ own (sel e) z) (λz.

assert (cheap z) λ_.

η ⋆))

Now we will work towards the dynamic negation of S 2 , starting with box S 2 .

box S 2 = box (useFind S 2 )

↠ box ( get ⋆ (λe. get ⋆ (λe ′ .

(case sel P (λz. car z ∧ own (sel e) z) e ′ of {inl z → η z; inr _ → presuppose! (λz. car z ∧ own (sel e) z)}) ≫= (λz.

assert (cheap z) (λ_.

η ⋆)))))

≈ get ⋆ (λe.

(case sel P (λz. car z ∧ own (sel e) z) e of {inl z → η z; inr _ → presuppose! (λz. car z ∧ own (sel e) z)}) ≫= (λz.

η (cheap z)))

We see that the meaning box S 2 is anaphoric, it uses get to find an antecedent for his and his car. Furthermore, depending on the retrieved context e, it might trigger a presupposition about the existence of his car. In reducing the expression, we have also allowed ourselves to collapse the two successive uses of get, since we have derived an equation for dynamic computations that tells us that get is idempotent under the handlers we use (see 7.2.5), hence the use of the ≈. To finish computing ¬ S 2 , we take box S 2 , replace the final η with an assert! and negate its argument.

amb : 1 ↣ 2

The amb operation allows us to branch into two different computations. We can imagine this as asking an oracle or flipping a coin. We give no input and we receive a Boolean: either T (inl ⋆) or F (inr ⋆). A handler for amb might then consult some oracle, flip (pseudo-)random coins, collect all the possibilities in a list or a set or just return one of the results by always answering T. If we look back to the algebraic formulation of λ computations given in Chapter 1, we find that amb corresponds to a single binary operation on computations. This algebraic notation will actually be more useful then the computational one we usually use and so we introduce the following:

We can now write a handler that tries both projecting a presupposition and accommodating it.

Now we need to include this handler into the lexical entries of our grammar, wherever presuppositions can be accommodated. Here, we can follow existing analyses. Projective DRT [131] lets presupposed content accommodate within DRSs on the projection line. Lebedeva's use of exceptions for presuppositions in TTDL [80] employs an exception handler (iacc) that allows for accommodation at every point where a discourse referent is being bound (i.e. at every dynamic existential quantification). We can achieve the same result in our λ analysis by including the maybeAccommodate in the box handler:

Now, if our semantics for the modal operator maybe and the attitude verb think use boxes, then we get as denotation of Example 24 a nondeterministic computation that yields the three readings mentioned above. Looking back at those three readings, [17] states that while they are all possible, the first reading (global accommodation at c 0 ) is strongly preferred to the other readings. This is generalized to the following empirically motivated principle: PGA (Preference for Global Accommodation): Global accommodation is preferred to nonglobal accommodation.

[17], 5.1 If it were only for this principle, we might wonder why we bothered with allowing accommodation in any DRS on the projection line in the first place if we are going to always prefer accommodating globally. However, there are other forces which push in the opposite direction and impose constraints on presupposition projection. The one that we will tend to in this section is the effect of variable binding. A proposition being presupposed cannot escape the scope of a binder that binds one of its variables. In [17], this is illustrated on the following example. (25) Most Germans wash their car on Saturday.

The expression their car triggers the presupposition of the existence of a car belonging to the referent of their. We could accommodate this presupposition locally, in the nucleus of the quantifier most Germans, giving the reading "Most Germans have a car and they wash it on Saturday.". We could also accommodate

box is composed of box, maybeAccommodate and useFind. We apply all of these handlers in turn. We start with useFind, where we assume that the sentence is uttered in a context in which the existence of his children was not established. This means that sel P will not find a referent within e and the presupposition will not be cancelled. We also rely on the idempotence of get to collapse the two gets into one and so useFind ends up having no effect. Next up is maybeAccommodate that tries both projecting the presupposition and accommodating it using introduce and assert. Finally, box translates the dynamic propositions that use introduce and assert into simple propositions. We have one proposition with a presupposition projecting out of it and another one in which the presupposition was accommodated using an existential quantifier. The dynamic negation will negate these propositions and wrap them in assert:

(presuppose (λy. children y (sel e)) (λy.

η (frightened y)))

+ (η (∃y. children y (sel e) ∧ frightened y)) ≫= (λa. assert! (¬a)))

↠ get ⋆ (λe.

(presuppose (λy. children y (sel e)) (λy. assert (¬(frightened y)) (λ_.

+ (assert (¬(∃y. children y (sel e) ∧ frightened y)) (λ_.

η ⋆)))

We now turn to the antecedent S 1 : a man gets angry.

↠ introduce ⋆ (λx. assert (man x) (λ_. assert (angry x) (λ_.

η ⋆)))

The denotation of Example 26 is ¬( S 1 ∧ ¬ S 2 ) and so we have to compute S 1 ∧ ¬ S 2 and then the dynamic negation of the result.

assert (man x) (λ_. assert (angry x) (λ_.

get ⋆ (λe.

(presuppose (λy. children y (sel e)) (λy. assert (¬(frightened y)) (λ_.

η ⋆)))

+ (assert (¬(∃y. children y (sel e) ∧ frightened y)) (λ_.

We start computing ¬( S

assert (man x) (λ_. assert (angry x) (λ_.

(presuppose (λy. children(y, sel (angry x :: man x :: x :: e))) (λy. assert (¬(frightened y)) (λ_.

η ⋆)))

+ (introduce ⋆ (λy. assert (children(y, sel (angry x :: man x :: x :: e))) (λ_. assert (¬(frightened y)) (λ_.

η ⋆))))

+ (assert (¬(∃y. children(y, sel (angry x :: man x ::

Presuppositions

Proof. We consider λ with the M ; N construction and the following two reduction rules.

This calculus, which we will call λ ;→

, is not confluent but, as we will show below, it is terminating. Since the reduction relation of λ We now need to show that adding η-reduction still preserves termination. The original proof stood on Lemma 3.5.44, which states that we can delay η-reduction until the very end of evaluation and which relies on the idea that η-reduction never opens up a new redex which would neccessitate the use of another rule. This is still the case since η-reduction cannot make a new ;-redex appear without actually inserting a new semicolon and because the two reduction rules for M ; N given above are not sensitive to the structure of M and N .

To prove that λ ; is confluent, we prove that → ; is confluent and that → ; and the reduction relation of λ commute. We prove the latter using Lemma 3.4.16, as we did for → η and λ -η in Lemma 3.4.17, and for the former we use the following lemma, which is a special case of Proposition 1.0.2 in [75]. Proof. We will proceed by proving that → ; is subcommutative (i.e. that ∀a, b, c.

)) using structural induction on the term a, as in 3.4.17. We will consider the relative positions of the redex in the reductions a → ; b and a → ; c.

1. If both reductions occurred within a proper subterm of a, then we use the induction hypothesis and the context closure of → ; (see the analogous proof of 3.4.17 for technical details).

2. If the reductions occurred in non-overlapping subterms, then we can take the common reduct d as the term in which both subterms have been reduced.

3. If the redex in a → ; b is the entire term a and the redex in a → ; c is a proper subterm of a:

Then a = M ; N for some M and N . We split the proof based on whether the redex R of a → ; c is a subterm of M or N and whether b is equal to M or N .

. Because of M ; N → ; M , we know that for every e, M (e) is ⊥-less and therefore so is

We will choose d = N . We immediately have b = N → = ; N = d. By the same argument is in the previous case, we have that In 7.3, we have already seen how to combine our treatment of anaphora with a treatment of presuppositions. We will extend the fragment from Chapter 7 with the effects from Chapter 6 using the same process that we have used when adding presuppositions:

1. We will translate any closed handlers used in lexical entries into open handlers. While closed handlers can often be simpler to compute with, they are no longer applicable in the presence of other effects. For an example of this process, look in 7.3.1, where we translate the box handler, which is used in entries that make use of dynamic negation, into an open handler.

2. We will update the existing entries in the grammar(s) to reflect any interactions between the lexical entries and phenomena present in both treatments. In the case of presuppositions, we have made it so that contexts can cancel presuppositions (7.

Dynamic Kernel

As per the methodology described in 6.5, we will start with a basic "seed" grammar into which we will incorporate treatments of diverse phenomena. The grammar that we will start with will be a small dynamic fragment, very much like the one in 7.2. 148 While in 7.2, we tried to keep our dynamic grammar as close as possible to the presentation of DRT in Kamp and Reyle's textbook [64], the grammar that we will use here will be more in line with the categorial tradition. Instead of using non-lexicalized rules such as  : V P -•N P -•N P -•S and  : CN -•N (which were standing in for the DRT construction rules CR.LITV and CR.LIN), we will be using lexicalized entries such as  : N P -• N P -• S and  : N . We first give the lexical items in our grammar and their syntactic types (i.e. the abstract signature). 148 We could have also started with a more basic fragment without any effects and add dynamics separately. However, adding dynamics would force us to change almost all of the fragment: every individual meaning would need to add its referent to the context and every propositional meaning would need to add the proposition to the context. Furthermore, as we have seen in 7.2.4, we would also change the type of sentence interpretations from F E (o) to F E (1). A very similar translation from a static grammar to a dynamic one is described in [80] (Definition 4.27).

204

Chapter 8. Composing the Effects

The effect signature E is the DRT effect signature from 7.2.3

The interpretation of the constants in our abstract signature is given next:

The interpretations are almost the same as the ones given in 7.2, with the following changes:

• We use the simplified entry for pronouns, derived in 7.2.5, to which we add gender markings.

• We also give interpretations to the two new constants, _._ and . We interpret the empty discourse  as a discourse which contributes nothing, a trivial computation that immediately returns the dummy value ⋆. 150 The discourse extension operator _._ is interpreted the same as the dynamic conjunction ∧, by chaining the evaluation of its constituents.

with an existential quantifier. Using introduce thus has the effect of installing an existential quantifier at the scope of the nearest enclosing box, much like the DRT construction rule for indefinites, CR.ID (see Figure 7.1), introduces a discourse referent to the nearest enclosing DRS. The objective of our semantics is to assign truth conditions to sentences. These truth conditions are expressed as propositions, terms of type o. As we progress, we will be adding more and more effects to implement a compositional semantics for "non-compositional" phenomena such as anaphora, presuppositions and conventional implicatures. We will define a handler that will strip away this extra structure and give us the truth conditions of a sentence in some default context.

The empty handler evaluates a meaning in the empty context nil, interpreting away the get operation. On the other hand, the box handler interprets away the introduce and assert operations, and so by composing them, we can interpret away all the effects in E DRT . The resulting handler, top, plays the role of a top-most (top-level) DRS: it is a box in an empty context (i.e. there is no other DRS that is accessible from this one).

Furthermore, if we look at the special case of the type of top when E = ∅, we get a pure computation (type F ∅ (o)) as the result. This means we can use the -• operator to get at the resulting proposition directly. The -• • top combinator (pronounced "cherry on top") gives us a formal way to associate a proposition to the denotation of a sentence or discourse (remember that S = D = F E (1) with E currently being E DRT ).

We will now integrate the effects that we have seen in Chapters 6 and 7 into our dynamic grammar. We will start with the effect that we have already seen interact with anaphora in Section 7.3.

Adding Presuppositions

We will be enriching our fragment with the following referring expressions: proper names such as John and Mary, possessive constructions expressing ownership or other relations (X's car, X's children, X's best friend…) and definite descriptions (the car). Here are the new entries into our abstract signature:

In order to give a meaning to these constructions, we will need some extra structure in our model. We will therefore add the following into our object signature:

We represent proper names in our models as predicates. The idea behind a predicate such as John is that John x should be true for any x which is called John.

Adding Presuppositions

207

Now we can describe how we extend our lexicon so that it covers the new constructions. The interpretation of the abstract types will stay the same, we will only change the effect signature to include the following two operations:

We extend the lexicon to the new constructions, using the new presuppose operation.

These entries are the same as the ones we have seen in Section 7.3. Besides introducing interpretations for the new lexical items, we will also modify some of the existing interpretations or combinators to reflect the interactions between the existing effects and the effect being added. In this chapter, whenever we will revise the interpretations of existing lexical items or the definitions of existing combinators, we will use the := symbol and if the right-hand side of the definition will make use of any of the symbols being redefined, those symbols will be meant to refer to the existing (old) definition.

The changes proposed above account for the following features of presuppositions:

• we add useFind to all boxes (box), including also the topmost one (top), so that presuppositional expressions referring to entities already available in the context do not trigger presuppositions

• we add maybeAccommodate to the box handler because a presupposition can be accommodated in any DRS on the projection line from the point where the presupposition was triggered

• we add accommodate to the top handler because we want any presuppositions that have been neither cancelled nor (locally) accommodated to be accommodated at the top level

• we add search to the top handler so that the proposition that we recover is the most preferred available reading of the sentence (w.r.t. the presupposition accommodation ambiguity in 7.3.4)

Below, we give the definition of the handlers for the new presuppose operation which account for the ways a presupposition can be eliminated: global accommodation (accommodate), local accommodation (maybeAccommodate) or cancellation (useFind).

These all come from Section 7.3, as well as the definitions of find and + given below.

Finally, we give the handler for the amb effect.

Adding Conventional Implicature

We move to conventional implicature, which we have treated (in isolation) in Section 6.3. We consider conventional implicatures triggered by supplements: nominal appositives and supplementary relative clauses. We will use the same abstract constants as in Section 6.3,   and . The constant   stands for the supplementary (appositive) use of the relative pronoun who.

We will not be adding any new predicates or operators to the object level: the new lexical items represent new syntactic structures and function words, not new concepts.

Adding Conventional Implicature



asImplicature (eq (η x) Y ) ≫= (λ_.

Let us compare the entries for   and  with those in Section 6.3. The first reason for the difference is that we now encode truth conditions as side effects: if we evaluate the relative clause, its truth conditions are contributed to the current context. We could separate the implicated truth conditions of the embedded clause from the (asserted) truth conditions of the surrounding material by wrapping the embedded clause in a box.

implicate i (λ_. η x))) However, if we do this, none of the discourse referents introduced within the supplement will be available in subsequent discourse. This was the behavior predicted for parentheticals by Nunberg [102]. However, in his theory of conventional implicature [108], Potts opposes this view and shows examples which seem to contradict Nunberg's position. This was further supported by corpus studies in [5]. Here is an example of anaphoric binding out of an appositive: 152 (29) John, who nearly killed a woman 1 with his car, visited her 1 in the hospital. Dynamic propositions contribute truth conditions (assert : o ↣ 1) and discourse referents (introduce : 1 ↣ ι) to the local context. In Section 6.3, we have introduced the operation implicate : o ↣ 1 which contributes the truth conditions of conventional implicatures to the global context. We will complement implicate with an operation introduce i : 1 ↣ ι for introducing discourse referents of conventional implicatures to the global context. We can now move at-issue content into the conventional implicature layer by treating assert as implicate and introduce as introduce i , which is exactly what the asImplicature handler does. If we review the lexical entry for   , we see that the at-issue content of the embedded relative clause C gets treated as an implicature in the embedding expression "X, who C".   = λCX. X ≫= (λx.

asImplicature (C (η x)) ≫= (λ_.

η x))

In particular in Example 29, the indefinite a woman in the sentence "x nearly killed a woman" uses the introduce operation to establish a new discourse referent. Upon being used as an appositive clause, this Chapter 8. Composing the Effects introduce turns into an introduce i , which will project to the global context, from which it will be able to bind upcoming pronouns. Therefore we get the desired binding in Example 29.

Finally, the implicatures signalled by the implicate and introduce i operations have to be resolved somewhere. We adopt the approach of Projective DRT [131] by interpreting conventional implicatures as belonging to the topmost box. top := top • withImplicatures withImplicatures : F E⊎E DRT ⊎{implicate,introduce i } (α) → F E⊎E DRT ⊎{assert,introduce} (α) withImplicatures = implicate: assert, introduce i : introduce

Connection to the Standalone Theory

The lexical entries and handlers introduced in this section have been quite different from the ones introduced in Section 6.3. This raises the issue of whether the analysis that was done in Section 6.3 is upheld in our extension. We will draw out the parallels between the original definitions and the new ones to show that:

• the most visible changes are due to us representing truth conditions as side effects

• the important change is the treatment of introduce which accounts for the binding potentinal of appositives (an interaction between anaphora and conventional implicature)

We start with the appositive relative clause constructor.

  = λCX. X ≫= (λx.

In the standalone treatment (seen on the right), we used a static grammar, where sentences denoted propositions. To turn the proposition into an implicature, all we had to do was to pass that proposition to the implicate operation. In our dynamic grammar, sentences use assert to convey their truth conditions and so we need to use a handler to pass these truth conditions to implicate, which is exactly what (the assert clause of) the asImplicature handler does. Now on to nominal appositives.  = λY X. X ≫= (λx.

We have refactored the original interpretation  ′ so that the actual differences are easier to spot. Again, we see the same difference as in   , where we use the asImplicature handler. The only other difference is that the condition about the equality of the referents of X and Y is not expressed as a computation that produces a proposition but as a computation that uses assert. This is again due to us having switched to a dynamic grammar that treats truth conditions as side effects. We now have a grammar that is both capable of licensing inverse scope and respects (certain) crossover constraints. 161 The rest of the grammar needs to be modified only insofar as handlers for introduce need to be replaced with handlers for fresh and push. The only other handler for introduce besides box is the asImplicature handler. asImplicature : F E⊎{assert,fresh,push} (α) → F E⊎{implicate,fresh i ,push i } (α) asImplicature = assert: implicate, fresh: fresh i , push: push i Since we no longer use introduce as a primitive operation, asImplicature will act on fresh and push, turning them into new operations, fresh i : 1 ↣ ι and push i : ι ↣ 1. The converse handler, withImplicatures, will therefore also need to be changed to treat fresh i and push i .

withImplicatures : F E⊎E DRT ⊎{implicate,fresh i ,push i } (α) → F E⊎E DRT ⊎{assert,fresh,push} (α) withImplicatures = implicate: assert, fresh i : fresh, push i : push

Connections to Other Solutions

We will draw parallels to two other approaches.

In the interpretations of  and ', we introduce an extra layer of computation. Then, instead of generalizing all other noun phrases to employ this extra layer, we added - and  as lexical items into our grammar, allowing us to use quantified noun phrases, which use this extra layer of computation, in contexts where an ordinary noun phrase was expected. The interpretation of  is the ≫= operator. This is reminiscent of the way of composing different monads proposed by Simon Charlow during Barker's and Bumford's ESSLLI 2015 course [13]. The idea is that we should not try to build some large monad that encompasses all aspects of meaning but rather build meanings in smaller, different monads, each meaning using only as much structure as it needs. The gluing together of the meanings is then performed by the parser which can insert ≫= for the relevant monads and other plumbing as necessary. This is also the kind of approach adopted by Giorgolo and Asudeh [50].

We also notice a similarity between our approach to inverse scope and that of Shan in [117]. Shan adopts multistage programming to suspend the evaluation of the context of the object until after the object itself has been evaluated, effectively displacing the evaluation of the object before the evaluation of the rest of the sentence. Our strategy is based on similar techniques: QR has the same effect of displacing evaluation and the denotations of  and ' suspend the evaluation of their anaphoric effects. A distinguishing sign of meta-programming or multistage programming are types like F E1 (F E2 (α)), i.e. programs producing programs, which is exactly the kind of type we use for QN P .

Limitations

Our treatment of inverse scope eliminates both primary crossover (the raised quantifier is the object, e.g. Example 33) and secondary crossover (the raised quantifier is embedded in the object, e.g. Example 34).

Examples from [120]: 160 Note that the quantifier ranging over mothers has wider scope than the one ranging over men, even though we raised the QNP every man over the whole sentence. This is because the referring expression his mother is presuppositional and is accommodated globally, above the meaning of this particular sentence. The context in which the operator sel he looks for an antecedent to the pronoun his is the context (man y) :: e, where e is the context in which the sentence is being evaluated. Since adding a proposition to a context is not supposed to change the set of possible antecedents, we write simply sel he e. 161 We will see shortly that there are situations for which our treatment is not sufficient.

In the rest of this section, we will discuss two topics related to restrictive relative clauses. First, we will outline an analysis which chooses a richer type of interpretations for nouns so that the lexical entry for the relative pronoun will be less ad-hoc. Then, we will discuss how relative clauses and other kinds of complex nouns interact with presuppositions and definite descriptions.

Different Interpretation for Nouns

At the start of this section, we have shown the challenge that is posed by folding in the meanings of sentences into the meanings of nouns when the two are interpreted completely differently:

If we change the type of interpretations of nouns so that truth conditions are expressed as side effects and the effects can depend on the individual argument, then there is no conflict any more and the lexical entry for   becomes trivial:

The schema underlying the use of computation types in such a grammar could be expressed the following way. Let the type of extensions A v of an atomic abstract type A be of the form a 1 → • • • → a n → b, where a i are atomic object types. Then we will use the type

as the interpretation A c of the atomic abstract type A. This means that the interpretations are call-by-value functions, taking n values as arguments and then producing a computation.

Then, if we adopt the use of side effects to encode truth conditions, as in our dynamic grammar, we get the following:

If we were to adopt this schema universally, we could also adapt the lifting operators and prove their conservativity by slightly modifying the proof of Observation 6.1.3.

Chapter 8. Composing the Effects

Finally, we could integrate this type of noun interpretations and the simpler lexical entry for the relative pronoun by adjusting the grammar that we have been building during this chapter.  = λx. assert! (man x)  = η man  = λx. assert! (woman x)  = η woman . . . . . .

N ≫= (λn. assert (n x) (λ_.

These are all the changes that need to be made to the grammar, except for the entries having to do with presuppositions ( and ), which we will deal with next.

Relative Clauses and Presuppositions

While changing the semantics of nouns and introducing restrictive relative clauses, we have so far ignored their interaction with presupposition triggers that depend on them. We will now give the semantics to these referring expressions, observe some of their deficiencies and propose solutions. 164  = λXN. X ≫= (λx.

presuppose! n)

The presuppose operation accepts static properties, functions of type ι → o, as arguments. Our noun is a dynamic property 165 , a function of type ι → F E (1). To go from dynamic to static, we can use the box handler to cast the introduce and assert operations down to propositions. Note that the same strategy is employed by Lebedeva in [80] The entry for the definite article uses the operator sel, on which our find operator is based. The sel operator is made compatible with dynamic properties in sel. This is done by applying a context e and the trivial continuation λe. ⊤ to the dynamic proposition P (λe. x). 166 presuppose! N ′ ))

- ≈ λX. X ≫= (λx.

presuppose! (λy. assert! (children y x)))

Finally, since we have changed the type (and therefore also the intended semantics) of the presuppose operation, we will also have to modify its handlers (accommodate, maybeAccommodate and useFind) accordingly. In accommodate and maybeAccommodate, instead of asserting P x, we evaluate it, letting it have its dynamic effects at wherever the presupposition is being accomodated. The useFind handler will work the same way as before but with a new definition for find which works on dynamic predicates of type ι → F E * (1). find will map dynamic predicates to static predicates using -•

• empty • box. The use of empty • box blocks any dynamic effects in the predicate P . 171 This can be intuitively understood as the listener considering whether there exists some x such that P x without committing the (dynamic) effects of P to the common ground. With all of this heavy machinery in place, we now have a system that can deal with sentences like Example 36 and Example 37. The noun phrases the man who owns a dog and the man who loves his dog both trigger presuppositions with dynamic content. This content is then accommodated globally and all the new discourse referents are available in subsequent discourse. (36) The man who owns a dog 1 loves it 1 .

(37) The man 1 who loves his 1 dog 2 treats it 2 well.

≈ presuppose! (λx. assert (man x) (λ_. introduce ⋆ (λy.

assert (dog y) (λ_. assert (own x y) (λ_. assert (love x y) (λ_.

η ⋆))))))

We also derive the intended readings behind Examples 38, 39, 40 and 41, but that was already the case before delving into dynamic presuppositions.

Summary

In this chapter, we have built up a single grammar that covered anaphora, presuppositions (of referring expressions), deixis (of first person pronouns), quantifiers and conventional implicatures (of appositive clauses). The grammar can derive the meanings of all the sentences we analyzed in Chapters 6 and 7 using the same abstract syntactic structure. 172

↠ ∃x. best-friend x s ∧ (∃y. dog y ∧ own x y ∧ say x (∀z. love y z))

172 With the exception of in-situ quantifiers which now use the - operator. 173 For the detailed process of computing the meaning of Example 42, take a look in Appendix B.

• Quantification

Our technique of using the scope operation follows approaches that propose the use of continuations in natural language [36, 12]. The type and the semantics of our scope operation match those of shift, a control operator for delimited continuations used to treat quantification in [115]. Instead of context levels, we use quantifier raising to account for scope ambiguity. As in Montague's work [98], we have a syntactic construction rule that takes a quantificational noun phrase and uses it to bind an N P variable within a sentence (QR : QN P -•(N P -•S)-•S). The syntactic type of QR is based on the type given to the determiners every and some in [105] (C every : N -• (N P -• S) -• S).

By composing  : N -• QN P and QR : QN P -• (N P -• S) -• S, we get λN. QR ( N ) :

N -• (N P -• S) -• S. In 6.4.2, we have also pointed out that a λ computation invoking a series of scope operations is like a nested sequence of quantifiers in Keller storage [66]. However, unlike Keller storage (and Cooper storage [32]), the quantifiers cannot be retrieved in any order since one could bind a variable in another. 184 Therefore, we solve ambiguity by other means (QR).

• Conventional Implicature Our analysis stems from Potts' dissertation on the logic of conventional implicatures [108]. This multidimensional approach to the semantics of conventional implicatures was adapted into a monadic treatment by Giorgolo, Asudeh et al in 2011 [51, 48]. Monadic treatments of conventional implicatures have also appeared in recent ESSLLI courses: the treatment of expressives by Kiselyov and Shan at ESSLLI 2013 [72] and by Barker and Bumford at ESSLLI 2015 [13]. The underlying monad in all the monadic treatments is the writer monad. The writer monad is parameterized by a monoid. Every computation in the monad is accompanied by an element of the monoid and composing computations has the effect of combining their monoidal components. In the case of the writer monad for conventional implicatures, the monoid is some monoid of implicatures, usually the conjunctive monoid on propositions. The structure needs to be a monoid because we need a neutral element for phrases without any conventional implicatures and we need associativity of the monoid to get associativity of the monad.

In the free monad approach, we can characterize the writer monad by a single operation which computations can use to communicate elements from the monoid. This is what we do in Section 6.3, with implicate : o ↣ 1 as the operation and accommodate' from 6.3.1 as the handler which defines the monoid (∧ as the binary operation in the implicate clause and ⊤ as the neutral element in the η clause). This treatment of conventional implicatures is equivalent to the existing monadic analyses.

However, in Section 8.3, we study the interaction of dynamics with conventional implicatures. In our approach, the at-issue truth conditions are communicated by the two operations assert : o ↣ 1 and introduce : 1 ↣ ι. We take our cue from Layered DRT [46] and Projective DRT [131] to do the same for conventional implicatures: we complement implicate : o ↣ 1 with introduce i : 1 ↣ ι. This way, the monadic structure behind conventional implicatures becomes similar to the one used for dynamics (continuations with state). Conventional implicatures become updates to the context which are not blocked by logical operators such as negation. In our system, we get a compositional semantics which can account for binding out of appositives, as in Example 29.

(29) John, who nearly killed a woman 1 with his car, visited her 1 in the hospital.

• Deixis

In his treatment of indexicals, Kaplan models meanings as characters, functions from contexts to intensions. Contexts have several components, among them the agent which is making the utterance. In our approach, we add getters for the components of the context. In dynamics, we use get : 1 ↣ γ to get the anaphoric part of the context, and in treating the first-person pronoun, we use speaker : 1 ↣ ι to recover the speaker of the utterance.

A

List of Examples

(

B Example from the Final Fragment

We dedicate this chapter to the following sentence:

(42) My best friend, who owns a dog 1 , said it 1 loves everyone.

This sentence features all of the aspects of language that we covered in Part II:

• we have the deictic first-person pronoun my

• we have the presupposition triggering noun phrase my best friend

• we have the appositive relative clause who owns a dog

• we have the anaphoric pronoun it, which is bound by an indefinite inside an appositive

• we have the quantificational noun phrase everyone

As with the examples in Chapter 7, we will proceed by incrementally building up the meanings of the parts of the sentence. We start with the clause it loves everyone. First, we introduce the noun phrase  : N P , which can be seen as a special case of the  : N -• N P determiner that already exists in our grammar.

Now, we move to the clause. The entry for the transitive verb loves tells us to evaluate the subject and the object, to assert that the relation love holds for the two, and to handle any scope operations using SI to enforce the "tensed clauses are scope islands" constraint.

 (- ) 

↠ SI ( get ⋆ (λe.

scope ∀ (λz.

push z (λ_. assert (love (sel it e) z) (λ_.

η ⋆)))))

↠ get ⋆ (λe.

∀ (λz. push z (λ_. assert! (love (sel it e) z))))

↠ get ⋆ (λe. assert (∀z. love (sel it e) z) (λ_.

η ⋆))

Appendix B. Example from the Final Fragment

We will now give a meaning to the verb phrase said it loves everyone. The verb said evaluates its complementary clause down to a proposition using the box handler. We will therefore first calculate the value of applying box to the meaning of it loves everyone. We can now plug this result into the lexical entry   .

  ( (- ) )

↠ λX. SI ( X ≫= (λx. get ⋆ (λe. assert (say x (∀z. love (sel it e) z)) (λ_.

η ⋆))) )

Now we move to the subject of the sentence. The meaning of the first-person pronoun me is obtained by asking the context for the identity of the speaker and the meaning of the possessive construction X's best friend is obtained by asking the context for an individual that is X's best friend. To obtain the meaning of the noun phrase my best friend, it suffices to chain/concatenate the two computations.

- 

↠ speaker ⋆ (λs.

presuppose (λx. assert! (best-friend x s)) (λx.

Next, we compute the meaning of the verb phrase owns a dog that occurs in the relative clause. The indefinite a dog introduces a discourse referent which it claims to be a dog.

introduce ⋆ (λy.

assert (dog y) (λ_. assert (own x y) (λ_.

According to the lexical entry for   , the verb phrase inside an appositive relative clause is applied to a variable x and passed through the asImplicature, which moves the contents of the relative clause from the at-issue layer to the layer of conventional implicatures.

asImplicature  ( ) (η x) ↠ asImplicature ( introduce ⋆ (λy.

assert (dog y) (λ_.

assert (own x y) (λ_.

To get the meaning of the noun phrase my best friend as modified by the appositive relative clause who owns a dog, we chain their computations.

presuppose (λx. assert! (best-friend x s)) (λx.

Finally, to compute the meaning of the whole sentence of Example 42, we chain the computation of the subject with the computation of the verb phrase.

  ( (- ) ) (  ( ( )) (- ))

↠ speaker ⋆ (λs.

presuppose (λx. assert! (best-friend x s)) (λx.

introduce i ⋆ (λy. implicate (dog y) (λ_.

implicate (own x y) (λ_. get ⋆ (λe. assert (say x (∀z. love (sel it e) z)) (λ_.

We now have all the instructions that tell us how to find the truth conditions of the sentence within any context. We can use the handler top s to get the meaning of the sentence within an "empty" context with the speaker s. The top handler is defined as a composition of all the partial handlers for the different aspects of our fragment. We will apply the handlers to the meaning of Example 42 one by one.

We label the meaning of Example 42 as t 0 and the successive applications of the handlers as t 1 , t 2 …

We start with the SI handler. Since the computation t 0 uses no scope operation, the SI handler will have no effect.

Next up is the withSpeaker s handler. This will resolve the speaker operation by replacing the speaker variable s by the hypothetical speaker s, i.e. the rest of the computation stays the same.

introduce i ⋆ (λy.

implicate (dog y) (λ_. implicate (own x y) (λ_.

get ⋆ (λe. assert (say x (∀z. love (sel it e) z)) (λ_.

Then we have the withImplicatures handler that will accommodate the conventional implicatures of the sentence as part of its truth conditions.

introduce ⋆ (λy. assert (dog y) (λ_.

assert (own x y) (λ_. get ⋆ (λe.

assert (say x (∀z. love (sel it e) z)) (λ_.

Next is the useFind handler that will try to look up a referent for the speaker's best friend within the context.

introduce ⋆ (λy. assert (dog y) (λ_. asssert (own x y) (λ_.

get ⋆ (λe. assert (say x (∀z. love (sel it e) z)) (λ_.

We know ahead of time that the context e in which the sentence will be evaluated will not contain the speaker's best friend and so we allow ourselves to reduce sel P (λx. best-friend x s) e to inr ⋆.

presuppose (λx. assert! (best-friend x s)) (λx. introduce ⋆ (λy.

assert (dog y) (λ_. assert (own x y) (λ_.

get ⋆ (λe. assert (say x (∀z. love (sel it e) z)) (λ_.

The presupposition is then accommodated by the accommodate handler.

introduce ⋆ (λy. assert (dog y) (λ_.

assert (own x y) (λ_. get ⋆ (λe. assert (say x (∀z. love (sel it e) z)) (λ_.

Next up is the box handler which takes care of the sentence dynamics. where e ′ = ((own x y) :: (dog y) :: y :: (best-friend x s) :: x :: nil) + + e The empty handler, which comes next, will identify the (anaphoric) context e in which the sentence is being evaluated as the empty context nil. The context e ′′ contains only two entities: the speaker's best friend x and his dog y. Assuming that anaphora resolution will choose the dog y as the referent of the pronoun it, we can reduce sel it e ′′ to y.

↠ η (∃x. best-friend x s ∧ (∃y. dog y ∧ own x y ∧ say x (∀z. love y z)))

By applying the top s composition of handlers, we have interpreted away all the operations. The result is of the form η A where A are the truth conditions of the sentence. To retrieve A from η A, we can use -• .

↠ ∃x. best-friend x s ∧ (∃y. dog y ∧ own x y ∧ say x (∀z. love y z))

C

Computer Mechanization of the Calculus

During the development of our approach, we have experimented with several implementations of effects and handlers. In our initial explorations, we used Kiselyov's extensible effects Haskell library [71, 2]. However, this made it difficult to separate our contribution from the details of the Haskell encoding of effects and handlers. In the next step, we turned to a programming language which included effects and handlers as first-class primitives, Bauer and Pretnar's Eff [16]. We have used Eff to prototype the grammars which led to us reporting our first results with effects and handlers in natural language [89].

Nevertheless, we found it difficult to develop larger grammars in a direct-style calculus without a suitable effect system. We designed λ to have a calculus in which evaluation (reduction) is independent of execution (the ordering of effects within computations). After the definition of λ started to stabilize, we looked at ways of mechanizing the calculus so as to be able to use a computer to assist us in exploring the calculus. λ is defined by a set of reduction rules and so we have used PLT Redex [42] to develop the mechanization of the calculus. Redex is a Racket library/domain-specific language for engineering and debugging reduction semantics. The formal language of terms and types, the typing rules and the reduction rules can all be written in a style close to the one used in academic papers. The formalization can then be used to automatically generate test cases for formal properties such as subject reduction, termination or progress.

We have formalized the syntax, typing rules and reduction rules using Redex. The source code can be found at: https://github.com/jirkamarsik/ling-eff/blob/master/redex/effects-and-handlers.rkt However, in order to be able to define the typing rules as judgment forms within Redex, we needed to include type annotations in our terms. Since λ types include computation types, which are indexed by effect signatures, which contain more types, the type-annotated terms become unwieldy. We have therefore also developed a formalization which omits the type system but keeps the original syntax. This second formalization can be found at: https://github.com/jirkamarsik/ling-eff/blob/master/redex/untyped-bananas.rkt We have commented this formalization and we have also included the complete final grammar that we introduce in Chapter 8. The formalization can be used as a source of machine proofs for reductions in λ . For example, we can use the formalization to verify the predicted meaning of Example 42 from Appendix B.

However, this formalization was not practical for experimenting with the calculus since normalizing a large λ term (such as the ones we saw in the linguistic examples throughout this dissertation) took about an hour when using Redex's reduction mechanisms. We have therefore also implemented a fast normalization procedure, which can be found at: https://github.com/jirkamarsik/ling-eff/blob/master/redex/fast-bananas.rkt In the rest of the appendix, we present an edited version of the implementation. (♭ e) (C e)) (x ::= variable-not-otherwise-mentioned) (c ::= variable-not-otherwise-mentioned) (OP ::= variable-not-otherwise-mentioned))

Appendix C. Computer Mechanization of the

;; We then extend the set of terms with the constructions for sum types and ;; product types from Section 1. 4 (OP e_a (λ (x_k) (C (λ (x) e_k)))) (side-condition (not (term (free-in x e_a)))) "C-OP") (--> (π1 (pair e_1 e_2)) e_1 "β.×1") (--> (π2 (pair e_1 e_2)) e_2 "β.×2") (--> (case (inl e) e_l e_r)

(e_l e) "β.+1") (--> (case (inr e) e_l e_r)

(e_r e) "β.+2")) BANANA+SPA e)) (--> (¬ (¬ e)) e) (--> (¬ (∃ (λ (x) e)))

) BANANA+SPA e))

;; prettify-logic makes logical operators infix and translates ;; lambda-binders to quantifiers.

(define prettify-logic (context-closure (reduction-relation BANANA+SPA (--> ((∧ any_1) any_2) (define-checked-term find (λ (P) (GET ★ (λ (e) (case ((selP (λ (x) (♭ (empty (box (P x)))))) e) (λ (x) (η x)) (λ (_) (! PRESUPPOSE P)))))))

;; The useFind handler tries resolving the presuppositions within its ;; arguments using find.

(define-checked-term useFind (handler-η (PRESUPPOSE (λ (P) (λ (k) (>>= (find P) k))))))

;; maybeAccommodate introduces ambiguity via the AMB operator. The search ;; handler resolves the ambiguity by choosing which of the two ;; possibilities to pursue. In the dissertation, we make this choice based ;; on whether or not the computations fail. In this mechanization, we ;; leave the ambiguity operator unresolved.

(define-checked-term search (handler-η (AMB (λ (_) (λ (k) ((k true) || (k false)))))))

;; We incorporate the possibility to accommodate a presupposition in every ;; DRS on the projection line by introducing maybeAccommodate to the box ;; handler. We also add useFind so that presuppositions can be (preferably) ;; found within the context without having to be accommodated. ;; common-noun : N ;; Common nouns all have the same kind of meaning and so we define a macro ;; to facilitate the population of the lexicon.

(define-syntax-rule (define-common-noun abstract object) (define-checked-term abstract (λ (x) (! ASSERT (object x)))))

(define-common-noun dog dog*)

;; indef : N → NP ;; This is the semantics of the indefinite article. In the dissertation, we ;; call this constructor 'a. Here we give it a longer name so as to avoid ;; confusion with the variable 'a. ;; in-situ : QNP → NP (define-checked-term in-situ (λ (Q) (>>= Q (λ (X) X))))

;; The following is a helper combinator for the lexical entry of ;; quantifiers. (trace x) is a term that evaluates to x but also ;; introduces x to the context. (define-checked-term trace (λ (x) (PUSH x (λ (_) (η x)))))

;