TL;DR: It is shown how list comprehensions may be generalised to an arbitrary monad, and how the resulting programming feature can concisely express in a pure functional language some programs that manipulate state, handle exceptions, parse text, or invoke continuations.
Abstract: Category theorists invented monads in the 1960's to concisely express certain aspects of universal algebra. Functional programmers invented list comprehensions in the 1970's to concisely express certain programs involving lists. This paper shows how list comprehensions may be generalised to an arbitrary monad, and how the resulting programming feature can concisely express in a pure functional language some programs that manipulate state, handle exceptions, parse text, or invoke continuations. A new solution to the old problem of destructive array update is also presented. No knowledge of category theory is assumed.
TL;DR: A fully modular interpreter based on monad transformers that incudes features missing from Steele's, Espinosa's, and Wadler's earlier efforts is designed and implemented in Gofer, whose constructor classes provide just the added power over Haskell's type classes to allow precise and convenient expression of the ideas.
Abstract: We show how a set of building blocks can be used to construct programming language interpreters, and present implementations of such building blocks capable of supporting many commonly known features, including simple expressions, three different function call mechanisms (call-by-name, call-by-value and lazy evaluation), references and assignment, nondeterminism, first-class continuations, and program tracing.The underlying mechanism of our system is monad transformers, a simple form of abstraction for introducing a wide range of computational behaviors, such as state, I/O, continuations, and exceptions.Our work is significant in the following respects. First, we have succeeded in designing a fully modular interpreter based on monad transformers that incudes features missing from Steele's, Espinosa's, and Wadler's earlier efforts. Second, we have found new ways to lift monad operations through monad transformers, in particular difficult cases not achieved in Moggi's original work. Third, we have demonstrated that interactions between features are reflected in liftings and that semantics can be changed by reordering monad transformers. Finally, we have implemented our interpreter in Gofer, whose constructor classes provide just the added power over Haskell's type classes to allow precise and convenient expression of our ideas. This implementation includes a method for constructing extensible unions and a form of subtyping that is interesting in its own right.
TL;DR: This work focuses on semantics for global and local state, showing that taking operations and equations as primitive yields a mathematical relationship that reflects their computational relationship.
Abstract: We model notions of computation using algebraic operations and equations. We show that these generate several of the monads of primary interest that have been used to model computational effects, with the striking omission of the continuations monad. We focus on semantics for global and local state, showing that taking operations and equations as primitive yields a mathematical relationship that reflects their computational relationship.
TL;DR: This work reformulates Moggi's monadic paradigm for modelling computational effects using the notion of enriched Lawvere theory, together with its relationship with strong monads; this emphasises the importance of the operations that produce the effects.
TL;DR: An incremental approach to the denotational semantics of complex programming languages based on the idea of monad transformer is proposed, by translating a programming language PL in a metalanguage ML(E), where some constants do not have a fixed intended interpretation in Cpo.
Abstract: We propose an incremental approach to the denotational semantics of complex programming languages based on the idea of monad transformer. The traditional way of giving denotational semantics to a programming language is to translate it into a metalanguage ML with a fixed intended interpretation in the category Cpo of cpos (or some variant of it). We depart from this approach by translating a programming language PL in a metalanguage ML(E), where some constants do not have a fixed intended interpretation in Cpo. These constants, specified in the signature ~, include a unary type constructor T and a collection of (polymorphic) operations for constructing terms of type TA. A key property of the translation is that programs of type A are translated into terms of type T(A°), where A ° is the translation of A. This approach does not yield any new semantics for PL, since eventually one has to interpret the constants in E, e.g. by translating them into ML. However, it is an integral part of the incremental approach to be able to change the interpretation of constants in E (without invalidating adequacy of the denotational semantics w.r.t, some given operational semantics), when extending the programming language. Suppose that PL is obtained from PLo by a sequence of simple extensions PLI C PLi+I and that we have a semantics for PLo, how can we built a semantics for PL? In terms of signatures for metalanguages the problem can be rephrased as follows: