In programming, some data acts as a resource (e.g., file handles, channels) subject to usage constraints. This poses a challenge to software correctness as most languages are agnostic to constraints on data. The approach of linear types provides a partial remedy, delineating data into resources to be used but never copied or discarded, and unconstrained values. Bounded Linear Logic provides a more fine-grained approach, quantifying non-linear use via an indexed-family of modalities. Recent work on coeffect types generalises this idea to graded comonads, providing type systems which can capture various program properties. Here, we propose the umbrella notion of graded modal types, encompassing coeffect types and dual notions of type-based effect reasoning via graded monads. In combination with linear and indexed types, we show that graded modal types provide an expressive type theory for quantitative program reasoning, advancing the reach of type systems to capture and verify a broader set of program properties. We demonstrate this approach via a type system embodied in a fully-fledged functional language called Granule, exploring various examples.Quantitative Program Reasoning with Graded Modal Types 110:3[2016]. Our graded modalities can thus be considered to be computationally trivial, i.e., not requiring additional underlying semantics, though we provide a graded possibility encapsulating I/O effects.At the moment, Granule is not designed as a general-use surface-level language. Rather, our aim is to demonstrate the reasoning power provided by combining linear, graded, and indexed types in the context of standard language features like data types, pattern matching, and recursion. A TASTE OF GRANULEWe begin with various example programs in Granule, building from the established concept of linear types up to the graded modalities of this paper. We show how linear and graded modal types allow us to document, discover, and enforce program properties, complementing and extending the reasoning provided by parametric polymorphism and indexed types.Granule syntactically resembles Haskell. Programs comprise mutually recursive definitions, with functions given by sequences of equations, using pattern matching to distinguish their cases. Toplevel definitions must have a type signature (inference and principal types is further work, ğ10). The T E X source of this section is a literate Granule file; everything here is real code. Ill-typed definitions are marked by ✗. We invite the reader to run the type checker and interpreter themselves. 1 LinearityTo ease into the syntax, the following are two well-typed polymorphic functions in Granule:Polymorphic type variables are explicit, given with their kind. These functions are both linear: they use their inputs exactly once. The id function is the linear function par excellence and flip switches around the order in which a function takes its arguments. From flip we can deduce that the structural exchange rule is allowed. However, the other two structural rules, weakening and con...
Effects and coeffects are two general, complementary aspects of program behaviour. They roughly correspond to computations which change the execution context (effects) versus computations which make demands on the context (coeffects). Effectful features include partiality, non-determinism, input-output, state, and exceptions. Coeffectful features include resource demands, variable access, notions of linearity, and data input requirements.The effectful or coeffectful behaviour of a program can be captured and described via type-based analyses, with fine grained information provided by monoidal effect annotations and semiring coeffects. Various recent work has proposed models for such typed calculi in terms of graded (strong) monads for effects and graded (monoidal) comonads for coeffects.Effects and coeffects have been studied separately so far, but in practice many computations are both effectful and coeffectful, e.g., possibly throwing exceptions but with resource requirements. To remedy this, we introduce a new general calculus with a combined effect-coeffect system. This can describe both the changes and requirements that a program has on its context, as well as interactions between these effectful and coeffectful features of computation. The effect-coeffect system has a denotational model in terms of effect-graded monads and coeffect-graded comonads where interaction is expressed via the novel concept of graded distributive laws. This graded semantics unifies the syntactic type theory with the denotational model. We show that our calculus can be instantiated to describe in a natural way various different kinds of interaction between a program and its evaluation context.
The version in the Kent Academic Repository may differ from the final published version. Users are advised to check http://kar.kent.ac.uk for the status of the paper. Users should always cite the published version of record.
Abstract. Effect systems were originally conceived as an inference-based program analysis to capture program behaviour-as a set of (representations of) effects. Two orthogonal developments have since happened. First, motivated by static analysis, effects were generalised to values in an algebra, to better model control flow (e.g. for may/must analyses and concurrency). Second, motivated by semantic questions, the syntactic notion of set-(or semilattice-) based effect system was linked to the semantic notion of monads and more recently to graded monads which give a more precise semantic account of effects. We give a lightweight tutorial explanation of the concepts involved in these two threads and then unify them via the notion of an effect-directed semantics for a control-flow algebra of effects. For the case of effectful programming with sequencing, alternation and parallelism-illustrated with music-we identify a form of graded joinads as the appropriate structure for unifying effect analysis and semantics.
scite is a Brooklyn-based organization that helps researchers better discover and understand research articles through Smart Citations–citations that display the context of the citation and describe whether the article provides supporting or contrasting evidence. scite is used by students and researchers from around the world and is funded in part by the National Science Foundation and the National Institute on Drug Abuse of the National Institutes of Health.
hi@scite.ai
10624 S. Eastern Ave., Ste. A-614
Henderson, NV 89052, USA
Copyright © 2024 scite LLC. All rights reserved.
Made with 💙 for researchers
Part of the Research Solutions Family.