xacid: (Default)
https://hal.inria.fr/inria-00587597

The understanding of continuation-passing style (CPS) translations, an historical source of denotational semantics for programming languages, benefits from notions brought by linear logic, such as focalisation, polarities and the involutive negation. Here we aim to show how linear logic helps as well when continuations are delimited, i.e. return and can be composed, in the sense of Danvy and Filinski. First we provide a polarised calculus with delimited control (first-class delimited continuations) which is, at the level of computation, a variant of Girard's polarised classical logic LC. It contains variants of delimited control calculi which spawned as answers to the question "what order of evaluation can we consider with delimited control?". Thus our polarised calculus is one answer which is unifying to some degree. Subsequently we decompose the calculus through polarised linear logic. The only difference with non-delimited continuations is the use of specific exponentials, that account for the specific semantics of the target of delimited CPS translation, as well as annotations of type-and-effect systems. As a by-product, we obtain an explanation of CPS translations through a factoring, each step of which accounts for distinct phenomena of CPS translations. Although the factoring also holds for non-delimited CPS translations, it did not appear in its entirety before.
xacid: (Default)
// I just have got this little Cartesian category ...

def id[A]: A => A = (a => a)
def[A, B, C] (f: B => C) o (g: A => B): (A => C) = a => f (g (a) )
def curry[A, B, C]: ((A, B) => C) => (A => (B => C) ) = f => a => b => f (a, b)
def uncurry[A, B, C]: (A => (B => C) ) => ((A, B) => C) = f => (a, b) => f (a) (b)
def swap[A, B, C]: ((A, B) => C) => ((B, A) => C) = f => (b, a) => f (a, b)
def flip[A, B, C]: (A => (B => C) ) => (B => (A => C) ) = curry o swap o uncurry

// ... so, finally, let's do something really crazy :) Read more... )
xacid: (Default)
https://bentnib.org/handlers-cps-journal.html

We give two distinct foundational implementations of all the kinds of handlers we consider: a continuation passing style (CPS) transformation and a CEK-style abstract machine. In both cases, the key ingredient is a generalisation of the notion of continuation to accommodate stacks of effect handlers. We obtain our CPS translation through a series of refinements as follows. We begin with a first-order CPS translation into untyped lambda calculus which manages a stack of continuations and handlers as a curried sequence of arguments. We then refine the initial CPS translation by uncurrying it to yield a properly tail-recursive translation, and then moving towards more and more intensional representations of continuations in order to support different kinds of effect handlers. Finally, we make the translation higher-order in order to contract administrative redexes at translation time. Our abstract machine design then uses the same generalised continuation representation as the CPS translation.
xacid: (Default)
https://bentnib.org/paramnotions-jfp.pdf

Moggi’s Computational Monads and Power et al ’s equivalent notion of Freyd category have captured a large range of computational effects present in programming languages. Examples include non-termination, non-determinism, exceptions, continuations, side-effects and input/output. We present generalisations of both computational monads and Freyd categories, which we call parameterised monads and parameterised Freyd categories, that also capture computational effects with parameters. Examples of such are composable continuations, side-effects where the type of the state varies and input/output where the range of inputs and outputs varies. By also considering structured parameterisation, we extend the range of effects to cover separated side-effects and multiple independent streams of I/O. We also present two typed λ-calculi that soundly and completely model our categorical definitions — with and without symmetric monoidal parameterisation — and act as prototypical languages with parameterised effects.
xacid: (Default)
Capability-Passing Style for Zero-Cost Effect Handlers

http://ps.informatik.uni-tuebingen.de/publications/schuster20capability.pdf

Effect handlers encourage programmers to abstract over repeated patterns of complex control flow. As of today, this abstraction comes at a significant price in performance. In this paper, we aim to achieve abstraction without regret for effect handlers.
We present a language for effect handlers in capability-passing style (λCap) and an implementation of this language as a translation to simply-typed lambda calculus in iterated continuation-passing style. A suite of benchmarks indicates that the novel combination of capability-passing style and iterated CPS enables significant speedups over existing languages with effect handlers or control operators. Our implementation technique is very general and allows us to generate code in any language that supports first-class functions.
We then identify a subset of programs for which we can further improve the performance and guarantee full elimination of the effect handler abstraction. To formally capture this subset, we refine λCap to λCap with a more restrictive type system. We present a type-directed translation for λCap that inserts staging annotations and prove that no abstractions or applications related to effect handlers occur in the translated program. Using this second translation we observe additional speedups in some of the benchmarks.

Zero-cost Effect Handlers by Staging (Technical Report)

http://ps.informatik.uni-tuebingen.de/publications/schuster19zero.pdf

Effect handlers offer ways to structure programs with complex control-flow patterns. Yet, current imple- mentations of effect handlers incur a significant price in performance for doing so. We present a language that makes it possible to eliminate the overhead introduced by using effect handlers to abstract over effect operations. We present a translation of this language to simply typed lambda calculus in continuation passing style that preserves the well-typedness of terms. We present a second translation that, guided by automatically inserted staging annotations, guarantees to eliminate abstractions and applications related to effect handlers. We implement the translations and generate code in multiple languages. We validate the efficiency of the generated code theoretically, by proving that the use of certain language constructs never leads to run-time reductions, and practically, with a suite of benchmarks comparing with existing implementations of effect handlers and control operators.

Typing, Representing, and Abstracting Control

http://ps.informatik.uni-tuebingen.de/publications/schuster18typing.pdf

A well known technique to implement programming languages with delimited control operators shift and reset is to translate programs into continuation passing style (CPS). We can iterate the CPS translation to obtain the CPS hierarchy and to implement a family of control operators shifti and reseti . This functional pearl retells the story of a family of delimited control operators and their translation to lambda calculus via the CPS hierarchy. Prior work on the CPS hierarchy fixes a level of n control operators for the entire program upfront, but we allow different parts of the program to live at different levels. It turns out that taking shift0 rather than shift as the basis for the family of control operators is essential for this. Our source language is a typed embedding in the dependently typed language Idris. Our target language is a HOAS embedding in Idris. The translation avoids administrative beta- and eta-redexes at all levels of the CPS hierarchy, by iterating well-known techniques for the non-iterated CPS translation.
xacid: (Default)
inline def compose[A, B, R] (f: A => R) (g: B => A): B => R = x => f (g (x) )
inline def flip[A, B, R] (f: A => B => R): B => A => R = x => y => f (y) (x)

// compose[A => A1, B => B1, R] ->
// -> (f: (A => A1) => R) (g: (B => B1) => (A => A1) ): (B => B1) => R = compose (f) (g)
// -> (f: (A => A1) => R) (g: A => (B => B1) => A1 ): (B => B1) => R =  compose (f) (flip (g) )
// -> (f: A / A1 ! R) flatMap (g: A => B / B1 ! A1 ): B / B1 ! R

// A / B ! R = (A => B) => R
type /[A, R] = A => R
type ![A, R] = A => R
// A / R ! R = (A => R) => R
type :#:[A, R] = A / R ! R

inline def[A, B, R, A1, B1] (f: A / A1 ! R) flatMap 
  (g: A => B / B1 ! A1): B / B1 ! R = compose (f) (flip (g) )
Read more... )
xacid: (Default)
https://www.irif.fr/~mellies/mpri/mpri-ens/articles/fuhrmann-direct-models-of-computational-lambda-calculus.pdf

We introduce direct categorical models for the computational lambda-calculus. Direct models correspond to the source level of a compiler whose target level corresponds to Moggi’s monadic models. That compiler is a generalised call-by-value CPS-transform. We get our direct models by identifying the algebraic structure on the Kleisli category that arises from a monadic model. We show that direct models draw our attention to previously inconspicuous, but important, classes of programs (e.g. central, copyable, and discardable programs), and we’ll analyse these classes exhaustively—at a general level, and for several specific computational effects. Moreover, we show that from each direct model K we can recover the monadic model from which K arises as the Kleisli category.
xacid: (Default)
https://hal.inria.fr/hal-00996742v1/document

Negation is not involutive in the 𝜆𝒞 calculus because it does not distinguish captured stacks from continuations. We show that there is a formulae-as-types correspondence between the involutive negation in proof theory, and a notion of high-level access to the stacks studied by Felleisen and Clements.
We introduce polarised, untyped, calculi compatible with exten- sionality, for both of classical sequent calculus and classical natural deduction, with connectives for an involutive negation. The invol- ution is due to the l delimited control operator that we introduce, which allows us to implement the idea that captured stacks, unlike continuations, can be inspected. Delimiting control also gives a con- structive interpretation to falsity. We describe the isomorphism there is between 𝐴 and ¬¬𝐴, and thus between ¬∀ and ∃¬.

One way to provide constructive contents to classical proofs is by considering variants of the Gödel-Gentzen double-negation translations, such as Friedman’s [13]. We can translate classical proofs of ⊢ 𝑃 into intuitionistic proofs of ⊢ (𝑃′ → 𝑅) → 𝑅, where 𝑃′ is the translation of 𝑃 and where 𝑅 is chosen arbitrarily. When 𝑃 is purely positive, then 𝑃 ′ does not depend on 𝑅 and, furthermore, we have 𝑃′ = 𝑃. Therefore, in this special case we can take 𝑅 = 𝑃 and deduce an intuitionistic proof of ⊢ (𝑃 → 𝑃 ) → 𝑃 and, in turn, one of ⊢ 𝑃 . In the other cases, the translation describes in fact how the behaviour of classical proofs depends on the context in which classical axioms are invoked. Thus the interpretation does not contradict intuitionism: the latter assumes that the behaviour of proofs is referentially transparent, while here we do not make such an assump- tion. This is why proofs of ∀𝐴, 𝐴 ∨ ¬𝐴 do not provide a decision procedure for 𝐴 in general.

As we will see, the computational contents of the De Morgan law is as simple to understand as: 1) capturing the stack of the form 𝑛⋅𝜋 that appears during the head reduction of the argument; 2) decomposing it into head and tail, and return a pair (𝑛, 𝗄𝜋 ) where 𝗄𝜋 is the captured form of the tail. This contrasts with the proof in the 𝜆𝒞 cal- culus, which is convoluted because captured contexts are identified with continuations. By continuation we mean the functional abstrac- tion of the remainder of a computation. Thus, the contents of the captured context, which is represented by a functional value, cannot be accessed in an immediate way.
xacid: (Default)
http://www-verimag.imag.fr/~riegl/thesis/thesis-print.pdf

A major breakthrough came with Timothy Griffin in 1990 [Gri90] who removed this restriction and extended the correspondence to classical logic through the callcc control operator [SS75] which captures the state of the environment. Intuitively, callcc allows us to go back in time to a previous point in the program and to make a different choice, i.e. take a different execution path. Although Peter Landin earlier introduced a control operator J [Lan65a, Lan65b] to explain the behavior of the goto instruction of Algol60 [BBG+60], Timothy Griffin was the first to type a control operator. This discovery is specially remarkable because it connects callcc and Peirce’s law which were both known for a long time, respectively thirty years and over a century, and that such a deep connection was never noticed before. Following this result, various techniques have been used to encompass classical logic into computation: classical λ-calculi like Michel Parigot’s λμ-calculus [Par92], Stefano Berardi’s interactive realizability [AB10] and Jean-Louis Krivine’s classical realizability [Kri09] to name a few. This document will focus on the last one.
xacid: (Default)
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.51.8448&rep=rep1&type=pdf

This paper addresses the problem of extending the formulae-as-types principle to classical logic. More precisely, we introduce a typed lambda-calculus (λ-LK→) whose inhabited types are exactly the implicative tautologies of classical logic and whose type assignment system is a classical sequent calculus. Intuitively, the terms of λ-LK→ correspond to constructs that are highly non-deterministic. This intuition is made much more precise by providing a simple model where the terms of λ-LK→ are interpreted as non-empty sets of (interpretations of) untyped lambda-terms. We also consider the system (λ-LK→ + cut) and investigate the relation existing between cut elimination and reduction. Finally, we show how to extend our system in order to take conjunction, disjunction and negation into account.
xacid: (Default)
https://www.irif.fr/~krivine/articles/Luminy04.pdf

Realizability in classical logic


Jean-Louis Krivine



Introduction



The essential aim is to explore the Curry-Howard correspondence : we want to associate a program with each mathematical proof and to consider each theorem as a specification, i.e. to find the common behavior of the programs associated with every proof of this theorem. It is a very difficult and very interesting problem, which I call the “ specification problem ” in what follows.
Read more... )
xacid: (Default)
http://sro.sussex.ac.uk/id/eprint/1439/1/streicherreus1998.pdf

One of the goals of this paper is to demonstrate that denotational semantics is useful for operational issues like implementation of functional languages by abstract machines. This is exemplified in a tutorial way by studying the case of extensional untyped call-by- name λ-calculus with Felleisen’s control operator C. We derive the transition rules for an abstract machine from a continuation semantics which appears as a generalization of the ¬¬-translation known from logic. The resulting abstract machine appears as an extension of Krivine’s machine implementing head reduction. Though the result, namely Krivine’s machine, is well known our method of deriving it from continuation semantics is new and applicable to other languages (as e.g. call-by-value variants). Further new results are that Scott’s D∞-models are all instances of continuation models. Moreover, we extend our continuation semantics to Parigot’s λμ-calculus from which we derive an extension of Krivine’s machine for λμ-calculus. The relation between continuation semantics and the abstract machines is made precise by proving computational adequacy results employing an elegant method introduced by Pitts.
xacid: (Default)
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.44.7943&rep=rep1&type=pdf

This paper reports preliminary work on the semantics of the continuation transform. Previous work on the semantics of continuations has concentrated on untyped lambda-calculi and has used primarily the mechanism of inclusive predicates. Such predicates are easy to understand on atomic values, but they become obscure on functional values. In the case of the typed lambda-calculus, we show that such predicates can be replaced by retractions. The main theorem states that the meaning of a closed term is a retraction of the meaning of the corresponding continuationized term.
xacid: (Default)
http://www.nuprl.org/documents/Murthy/EvaluationSemantics.pdf

https://ieeexplore.ieee.org/document/151634

It is shown how to interpret classical proofs as programs in a way that agrees with the well-known treatment of constructive proofs as programs and moreover extends it to give a computational meaning to proofs claiming the existence of a value satisfying a recursive predicate. The method turns out to be equivalent to H. Friedman's (Lecture Notes in Mathematics, vol.699, p.21-28, 1978) proof by A-transition of the conservative extension of classical cover constructive arithmetic for II/sub 2//sup 0/ sentences. It is shown that Friedman's result is a proof-theoretic version of a semantics-preserving CPS-translation from a nonfunctional programming language back to a functional programming language. A sound evaluation semantics for proofs in classical number theory (PA) of such sentences is presented as a modification of the standard semantics for proofs in constructive number theory (HA). The results soundly extend the proofs-as-programs paradigm to classical logics and to programs with the control operator, C
xacid: (Default)
Assigning a morphism to each CPS calculus judgement is made somewhat awkward by the fact that these judgements have only premises (typing for names), but no conclusions (type for the whole term), so that there does not seem to be a canonical choice for the codomain of its denotation. This is perhaps surprising, but we would argue that CPS is so low-level that even composition is not fundamental, but a relatively involved idiom from its perspective.

We could either choose a “dummy” codomain (the corresponding continuation never being used) or single out one of the names in a judgement as the current continuation corresponding to the codomain.
xacid: (Default)
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.84.1959&rep=rep1&type=pdf

Haskell Is Not Not ML

Ben Rudiak-Gould, Alan Mycroft1, and Simon Peyton Jones

Abstract.

We present a typed calculus IL (“intermediate language”) which supports the embedding of ML-like (strict, eager) and Haskell-like (non-strict, lazy) languages, without favoring either. IL’s type system includes negation (continuations), but not implication (function arrow). Within IL we find that lifted sums and products can be represented as the double negation of their unlifted counterparts. We exhibit a compilation function from IL to AM—an abstract von Neumann machine—which maps values of ordinary and doubly negated types to heap structures resembling those found in practical implementations of languages in the ML and Haskell families. Finally, we show that a small variation in the design of AM allows us to treat any ML value as a Haskell value at runtime without cost, and project a Haskell value onto an ML type with only the cost of a Haskell deepSeq. This suggests that IL and AM may be useful as a compilation and execution model for a new language which combines the best features of strict and non-strict functional programming.
xacid: (Default)
http://www.lfcs.inf.ed.ac.uk/reports/97/ECS-LFCS-97-376/ECS-LFCS-97-376.pdf

Categorical Structure of Continuation Passing Style
Hayo Thielecke
Doctor of Philosophy University of Edinburgh 1997

Abstract

This thesis attempts to make precise the structure inherent in Continuation Passing Style (CPS). We emphasize that CPS translates λ-calculus into a very basic calculus that does not have functions as primitive.

We give an abstract categorical presentation of continuation semantics by taking the continuation type constructor ¬ (or cont in Standard ML of New Jersey) as primitive. This constructor on types extends to a contravariant functor on terms which is adjoint to itself on the left; restricted to the subcategory of those programs that do not manipulate the current continuation, it is adjoint to itself on the right.

The motivating example of such a category is built from (equivalence classes of typing judgements for) continuation passing style (CPS) terms. The categorical approach suggests a notion of effect-free term as well as some operators for manipulating continuations. We use these for writing programs that illustrate our categorical approach and refute some conjectures about control effects.

A call-by-value λ-calculus with the control operator callcc can be interpreted. Arrow types are broken down into continuation types for argument/result- continuations pairs, reflecting the fact that CPS compiles functions into a special case of continuations. Variant translation are possible, among them “lazy” call- by-name, which can be derived by way of argument thunking, and a genuinely call-by-name transform. Specialising the semantics to the CPS term model allows a rational reconstruction of various CPS transforms.

Read more... )
xacid: (Default)
https://www.semanticscholar.org/paper/A-Formulae-as-Types-Interpretation-of-Subtractive-Crolard/5c4363af97178d0ed468b6dc83b377a4f874fde6

https://pdfs.semanticscholar.org/5c43/63af97178d0ed468b6dc83b377a4f874fde6.pdf

A Formulae-as-Types Interpretation of Subtractive Logic

The computational interpretation of classical logic is usually given by a λ-calculus extended with some form of control (such as the famous call/cc of Scheme or the catch/throw mechanism of Lisp) or similar formulations of first-class continuation constructs. Continuations are used in denotational semantics to describe control commands such as jumps. They can also be used as a programming technique to simulate backtracking and coroutines. For instance, first-class continuations have been successfully used to implement Simula-like cooperative coroutines in Scheme [53, 18, 19]. This approach has been extended in the Standard ML of New Jersey (with the typed counterpart of Scheme’s call/cc [15]) to provide simple and elegant implementations of light-weight processes (or threads), where concurrency is obtained by having individual threads voluntarily suspend themselves [48, 42] (providing time-sliced processes using pre-emptive scheduling requires additional run-time system support [5, 47]). The key point in these implementations is that control operators make it possible to switch between coroutine contexts, where the context of a coroutine is encoded as its continuation.

The definition of a catch/throw mechanism is straightforward in the λμ-calculus: just
set catch α t ≡ μα[α]t and throw α t ≡ μδ[α]t where δ is a name which does not occur in t (see [7] for a study of the sublanguage obtained when we restrict the λμ-terms to these
operators). Then a name α may be reified as the first-class continuation λx.throw α x.
However, the type of such a λμ-term is the excluded-middle ⊢ Aα; ¬A. Thus, a continuation cannot be a first-class citizen in a constructive logic. To figure out what kind of second-order logic, in which ∨ , ∧ , ∃, ∃ are definable from → , ∀, ∀ . Since we are also interested in the subformula property, we shall restrict ourselves to the propositional framework where any connective is taken as primitive and where the proof normalization process includes permutative conversions [12]. Such an extension of CND with primitive conjunction and disjunction has already been investigated by Pym, Ritter and Wallen [40, 41, 39] and de Groote [12].
restricted use of continuations is allowed in SND→∨∧, we observe that in the restricted →+×λμ -calculus, even if continuations are no longer first-class objects, the ability of context-switching remains (in fact, this observation is easier to make in the framework of abstract state machines). However, a context is now a pair ⟨environment, continuation⟩.
Note that such a pair is exactly what we expect as the context of a coroutine, since a
coroutine should not access the local environment (the part of the environment which is
→+× not shared) of another coroutine. Consequently, we say that a λμ -term t is safe with
respect to coroutine contexts (or just safe for short) if no coroutines of t access the local environment of another coroutine.
The extension of this interpretation to SND→∨∧− is now straightforward. We already
know (from its definition in classical logic) that subtraction is a good candidate to type a
pair ⟨environment, continuation⟩. SND→∨∧− is thus interpreted as a type system for →+×−
first-class coroutines. The dual restriction from the safe λμ -calculus just ensures that one cannot obtain full-fledged first-class continuations back from first-class coroutines.

If we forget about linearity (which has of course many consequences on the resulting system), the main advantages of our approach are the following ones:
• We propose a computational interpretation of our restriction (as coroutines which do not access the local environment on another coroutine ).
• Our restriction is symmetrical and thus easily extends to duality. This allows us to propose a computational interpretation of subtraction (as a type constructor for first-class coroutines ).

Profile

xacid: (Default)
xacid

April 2021

S M T W T F S
    123
45678910
11121314151617
18192021222324
252627282930 

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 20th, 2025 01:30 am
Powered by Dreamwidth Studios