Monads and Effects
2002, Lecture Notes in Computer Science
https://doi.org/10.1007/3-540-45699-6_2…
81 pages
1 file
Sign up for access to the world's latest research
Abstract
A tension in language design has been between simple semantics on the one hand, and rich possibilities for side-effects, exception handling and so on on the other. The introduction of monads has made a large step towards reconciling these alternatives. First proposed by Moggi as a way of structuring semantic descriptions, they were adopted by Wadler to structure Haskell programs. Monads have been used to solve long-standing problems such as adding pointers and assignment, inter-language working, and exception handling to Haskell, without compromising its purely functional semantics. The course introduces monads, effects, and exemplifies their applications in programming (Haskell) and in compilation (MLj). The course presents typed metalanguages for monads and related categorical notions, and then describes how they can be further refined by introducing effects.
Related papers
ACM SIGPLAN Notices
Abstract. The combination of probabilistic and nondeterministic choice in program calculi is a notoriously tricky problem, and one with a long history. We present a simple functional programming approach to this challenge, based on algebraic theories of computational effects.
ACM SIGPLAN Notices, 1992
This report is the official specification of the Haskell language and should be suitable for writing programs and building implementations. It is not a tutorial on programming in Haskell such as the 'Gentle Introduction ' [5], so some familiarity with functional languages is assumed. Version 1.4 of the report was unveiled in 1997. It makes some minor corrections to version 1.3 and adds a few new features as described below. Version 1.4 is described in two separate documents: the Haskell Language Report (this document) and the Haskell Library Report . For the first time, we distinguish between Prelude and Library entities. Entities defined by the Prelude, a module named Prelude, are in scope unless explicitly hidden. Entities defined in library modules are in scope only if that module is explicitly imported. The library modules specified by Haskell are described in the Haskell Library Report. Monadic I/O has proven to be more general and in many respects simpler than the streambased I/O system used in Haskell 1.2. Here are the highlights of the I/O definition. • We define a monadic programming model for Haskell. Expressions of type IO a denote computations that may engage in I/O before returning an answer of type a. • The IO monad admits computations that fail and recovers from such failures. • We define a new type of handles, to mediate I/O operations on files and other I/O devices. Handles are part of the I/O library. • We define input polling and input of characters. In contrast, Haskell 1.2 represented character input as a single String (that is, a lazy list of characters), containing all the characters available for input throughout the program execution. • Monadic I/O provides an extensible framework capable of incorporating advanced operating system and GUI interfaces in libraries. • Monadic programming has been made more readable through the introduction of a special do syntax.
Theoretical Computer Science, 1992
Lecture Notes in Computer Science, 2011
Monads provide a greatly useful capability to pure languages in simulating side-effects, but implementations such as the Monad Transformer Library [1] in Haskell prohibit reuse of those side-effects such as threading through two different states without some explicit workaround. Monad Factory provides a straightforward solution for opening the non-proper morphisms by indexing monads at both the type-level and term-level, allowing 'copies' of the monads to be created and simultaneously used within even the same monadic transformer stack. This expands monads' applicability and mitigates the amount of boilerplate code we need for monads to work together, and yet we use them nearly identically to non-indexed monads.
2021
Monads govern computational side-effects in programming semantics. They can be combined in a ''bottom-up'' way to handle several instances of such effects. Indexed monads and graded monads do this in a modular way. Here, instead, we equip monads with fine-grained structure in a ''top-down'' way, using techniques from tensor topology. This provides an intrinsic theory of local computational effects without needing to know how constituent effects interact beforehand. Specifically, any monoidal category decomposes as a sheaf of local categories over a base space. We identify a notion of localisable monads which characterises when a monad decomposes as a sheaf of monads. Equivalently, localisable monads are formal monads in an appropriate presheaf 2-category, whose algebras we characterise. Three extended examples demonstrate how localisable monads can interpret the base space as locations in a computer memory, as sites in a network of interacting agents ...
2012
Monads are a concept of category theory which can be used to structure functional programs or even define nonstandard interpretations of the λ-calculus. These nonstandard functional languages share many of Lucid’s unusual features, such as the distinction between synchronic and general functions. In fact Lucid is exactly one of these languages, determined by a simple stream monad. We therefore propose that monadic functional programming is the appropriate meaning of “Intensional Programming”, with “Indexical Programming” reserved for languages in which intensions are indexed families of extensions. 1 An Unexpected Bounty Every year at ISLIP we have at least one soul-searching discussion on the topic “what is intensional programming?” Recently we added a new twist, an animated debate about “indexical” versus “intensional” programming. This new schism will undoubtedly cause even outsiders to be even more baffled than ever by the slippery notion of intensionality. At the same time, we ...
2002
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. This work is supported by EPSRC grant GR/M56333 and a British Council grant. may also prove useful when manipulating programs, e.g., for optimisation. We regard it as positive that there are no algebraic operations and equations in the sense of the theorem yielding the continuations monad, taking that as reflecting its differing computational nature.
1995
These notes discuss the simultaneous use of generalised fold operators and monads to structure functional programs. Generalised fold operators structure programs after the decomposition of the value they consume. Monads structure programs after the computation of the value they produce. Our programs abstract both from the recursive processing of their input as well as from the side-effects in computing their output.
The monadic style of language specification [6, 16, 15, 26] has the advantages of modularity and extensibility: it is simple to add or change features in an interpreter to reflect modifications in the source language. It has proven difficult to extend the method to compilation, because there is considerable interaction between different features. We demonstrate that by introducing machine-like stores (code and data) into the monadic semantics (to achieve pass separation [12]) and then partially evaluating the resulting semantic expressions, we can achieve many of the same advantages for a compiler as for an interpreter. A number of language constructs and features are compiled: expressions, while loops, CBV and CBN evaluation of -expressions, dynamic scoping, and various imperative features. The treatment of recursive procedures is outlined as well. The resulting method allows compilers to be constructed in a mix-and-match fashion just as in a monad-structured interpreter. K...

Loading Preview
Sorry, preview is currently unavailable. You can download the paper by clicking the button above.