HOME

TheInfoList



OR:

In
computing Computing is any goal-oriented activity requiring, benefiting from, or creating computer, computing machinery. It includes the study and experimentation of algorithmic processes, and the development of both computer hardware, hardware and softw ...
, an effect system is a
formal system A formal system is an abstract structure and formalization of an axiomatic system used for deducing, using rules of inference, theorems from axioms. In 1921, David Hilbert proposed to use formal systems as the foundation of knowledge in ma ...
that describes the computational effects of computer programs, such as
side effect In medicine, a side effect is an effect of the use of a medicinal drug or other treatment, usually adverse but sometimes beneficial, that is unintended. Herbal and traditional medicines also have side effects. A drug or procedure usually use ...
s. An effect system can be used to provide a compile-time check of the possible effects of the program. The effect system extends the notion of type to have an "effect" component, which comprises an effect kind and a region. The effect kind describes ''what'' is being done, and the region describes ''with what'' (parameters) it is being done. An effect system is typically an extension of a
type system In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
. The term "type and effect system" is sometimes used in this case. Often, a type of a value is denoted together with its effect as ''type ! effect'', where both the type component and the effect component mention certain regions (for example, a type of a mutable memory cell is parameterized by the label of the memory region in which the cell resides). The term "algebraic effect" follows from the type system. Effect systems may be used to prove the external purity of certain internally impure definitions: for example, if a function internally allocates and modifies a region of memory, but the function's type does not mention the region, then the corresponding effect may be erased from the function's effect.


Examples

Some examples of the behaviors that can be described by effect systems include: * Reading, writing or allocating memory: the effect kind is ''read'', ''write'', ''allocate'' or ''free'', and the region is the point of the program where allocation was performed (i.e., each program point where allocation is performed is assigned a unique label, and region information is statically propagated along the dataflow). Most functions working with memory will actually be polymorphic in the region variable: for example, a function that swaps two locations in memory will have type . * Working with resources, such as files: for example, the effect kind may be ''open'', ''read'' and ''close'', and again, the region is the point of the program where the resource is opened. * Control transfers with continuations and long jumps: the effect kind may be '' goto'' (i.e. the piece of code may perform a jump) and '' comefrom'' (i.e. the piece of code may be the target of a jump), and the region denotes the point of the program from which or to which the jump may be performed. From a programmer's point of view, effects are useful as it allows for separating the implementation (''how'') of specific actions from the specification of what actions to perform. For example, an ''ask name'' effect can read from either the console, pop a window, or just return a default value. The control flow can be described as a blend of ''yield'' (in that the execution continues) and ''throw'' (in that an unhandled effect propagates down until handled).


Implementations


Core feature

* Koka is a
statically typed In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
functional programming In computer science, functional programming is a programming paradigm where programs are constructed by Function application, applying and Function composition (computer science), composing Function (computer science), functions. It is a declarat ...
language with algebraic effect handlers as a main feature. * Eff is a statically typed functional programming language centered around algebraic effect handlers. *
Unison Unison (stylised as UNISON) is a Great Britain, British trade union. Along with Unite the Union, Unite, Unison is one of the two largest trade unions in the United Kingdom, with over 1.2 million members who work predominantly in public servic ...
is a statically typed functional programming language with algebraic effect handlers (called "abilities" in the language) as a core part of the type system.
Effekt
is a research language centered around effect handlers and polymorphic effects.


Full support

*
Haskell Haskell () is a general-purpose, statically typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research, and industrial applications, Haskell pioneered several programming language ...
is a statically typed functional programming language with several packages that allow for encoding of effects. However, Haskell is generally more focused on monads. * OCaml 5.0 introduced support for experimental effect handler primitives, with plans to introduce a proper high-level syntax in the future.


Partial support and prototypes

* Scala 3.1 is a statically typed, functional and object oriented programming language with experimental support for effects that is limited to exceptions, in the form of a CanThrow capability. *
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
is a statically typed, object oriented programming language; its checked exceptions are a relatively limited example of an effect system. Only one effect kind — throws — is available, there is no way to resume with a value, and they cannot be used with functions (only methods) unless the function implements a custom @FunctionalInterface.


References


Textbook chapters

* *


Overview papers

*


Further reading

* * {{DEFAULTSORT:Effect System Program analysis Type theory