HOME

TheInfoList



OR:

In
computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes, and development of both hardware and software. Computing has scientific, ...
, an effect system is a
formal system A formal system is an abstract structure used for inferring theorems from axioms according to a set of rules. These rules, which are used for carrying out the inference of theorems from axioms, are the logical calculus of the formal system. A fo ...
that describes the computational effects of computer programs, such as
side effect In medicine, a side effect is an effect, whether therapeutic or adverse, that is secondary to the one intended; although the term is predominantly employed to describe adverse effects, it can also apply to beneficial, but unintended, consequence ...
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 to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progra ...
. 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 GoTo (goto, GOTO, GO TO or other case combinations, depending on the programming language) is a statement found in many computer programming languages. It performs a one-way transfer of control to another line of code; in contrast a function c ...
'' (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 KOKA (980 AM) is an AM radio station, paired with an FM relay translator, licensed to Shreveport, Louisiana, and serving the Shreveport-Bossier City metropolitan area with an Urban contemporary gospel format. The station is currently under owne ...
is a statically typed
functional programming In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions tha ...
language with algebraic effect handlers as a main feature. * Eff is a statically typed functional programming language centered around algebraic effect handlers. *
Unison In music, unison is two or more musical parts that sound either the same pitch or pitches separated by intervals of one or more octaves, usually at the same time. ''Rhythmic unison'' is another term for homorhythm. Definition Unison or per ...
is a statically typed functional programming language with algebraic effect handlers (called "abilities" in the language) as a core part of the type system.


Full Support

* Haskell is a statically typed functional programming language with several packages that allow for encoding of effects. However, Haskell is generally more focused on monads.


Partial Support and Prototypes

* Scala 3.1 is a statically typed, functional and
object oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form o ...
programming language with experimental support for effects that is limited to exceptions, in the form of a CanThrow capability. *
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
is a statically typed, object oriented programming language; its
checked exception In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, ...
s 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. *
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
is a dynamically typed language, it has a proposal that implements algebraic effects.


References


Textbook chapters

* *


Overview papers

*


Further reading

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