<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.formulasearchengine.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=155.99.204.81</id>
	<title>formulasearchengine - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.formulasearchengine.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=155.99.204.81"/>
	<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/wiki/Special:Contributions/155.99.204.81"/>
	<updated>2026-09-02T15:48:12Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.47.0-wmf.7</generator>
	<entry>
		<id>https://en.formulasearchengine.com/w/index.php?title=Winter%27s_formula&amp;diff=24128</id>
		<title>Winter&#039;s formula</title>
		<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/w/index.php?title=Winter%27s_formula&amp;diff=24128"/>
		<updated>2013-12-12T21:52:36Z</updated>

		<summary type="html">&lt;p&gt;155.99.204.81: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{single source|date=June 2013}}&lt;br /&gt;
{{for|families of option contracts in finance|Option style}}&lt;br /&gt;
&lt;br /&gt;
In [[programming language]]s (especially [[functional programming]] languages) and [[type theory]], an &#039;&#039;&#039;option type&#039;&#039;&#039; or &#039;&#039;&#039;maybe type&#039;&#039;&#039; is a [[parametric polymorphism|polymorphic type]] that represents encapsulation of an optional value; e.g. it is used as the return type of functions which may or may not return a meaningful value when they are applied.  It consists of either an empty constructor (called &#039;&#039;None&#039;&#039; or &#039;&#039;Nothing&#039;&#039;), or a constructor encapsulating the original data type A (written &#039;&#039;Just&#039;&#039; A or &#039;&#039;Some&#039;&#039; A). Outside of functional programming, these are known as [[nullable type]]s.&lt;br /&gt;
&lt;br /&gt;
In the [[Haskell programming language|Haskell]] language, the option type (called &#039;&#039;Maybe&#039;&#039;) is defined as &amp;lt;code&amp;gt;data Maybe a = Just a | Nothing&amp;lt;/code&amp;gt;. In the [[OCaml]] language, the option type is defined as &amp;lt;code&amp;gt;type &#039;a option = None | Some of &#039;a&amp;lt;/code&amp;gt;. In the [[Scala_(programming_language)|Scala]] language, [http://www.scala-lang.org/api/current/scala/Option.html Option] is defined as parametrized abstract class &amp;lt;code&amp;gt;  &#039;.. Option[A] = if (x == null) None else Some(x)..&amp;lt;/code&amp;gt;. In the [[Standard ML]] language, the option type is defined as &amp;lt;code&amp;gt;datatype &#039;a option = NONE | SOME of &#039;a&amp;lt;/code&amp;gt;. In the [[Rust (programming language)|Rust]] language, it is defined as &amp;lt;code&amp;gt;enum Option&amp;lt;T&amp;gt; { None, Some(T) }&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In [[type theory]], it may be written as: &amp;lt;math&amp;gt;A^{?} = A + 1&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In languages that have [[tagged union]]s, as in most [[functional programming]] languages, option types can be expressed as the tagged union of a [[unit type]] plus the encapsulated type.&lt;br /&gt;
&lt;br /&gt;
In the [[Curry-Howard correspondence]], option types are related to the [[absorption law|annihilation law]] for ∨: x∨1=1.&lt;br /&gt;
&lt;br /&gt;
An option type can also be seen as a [[collection (computing)|collection]] containing either a single element or zero elements.&lt;br /&gt;
&lt;br /&gt;
== The option monad ==&lt;br /&gt;
The option type is a [[monads in functional programming|monad]] under the following functions:&lt;br /&gt;
:&amp;lt;math&amp;gt;\text{return}\colon A \to A^{?} = a \mapsto \text{Just} \, a&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\text{bind}\colon A^{?} \to (A \to B^{?}) \to B^{?} = a \mapsto f \mapsto \begin{cases} \text{Nothing} &amp;amp; \text{if} \ a = \text{Nothing}\\ f \, a&#039; &amp;amp; \text{if} \ a = \text{Just} \, a&#039; \end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
We may also describe the option monad in terms of functions &#039;&#039;return&#039;&#039;, &#039;&#039;fmap&#039;&#039; and &#039;&#039;join&#039;&#039;, where the latter two are given by:&lt;br /&gt;
:&amp;lt;math&amp;gt;\text{fmap} \colon (A \to B) \to A^{?} \to B^{?} = f \mapsto a \mapsto \begin{cases} \text{Nothing} &amp;amp; \text{if} \ a = \text{Nothing}\\ \text{Just} \, f \, a&#039; &amp;amp; \text{if} \ a = \text{Just} \, a&#039; \end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\text{join} \colon {A^{?}}^{?} \to A^{?} = a \mapsto \begin{cases} \text{Nothing} &amp;amp; \text{if} \ a = \text{Nothing}\\ \text{Nothing} &amp;amp; \text{if} \ a = \text{Just} \, \text{Nothing}\\ \text{Just} \, a&#039; &amp;amp; \text{if} \ a = \text{Just} \, \text{Just} \, a&#039; \end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The option monad is an additive monad: it has &#039;&#039;Nothing&#039;&#039; as a zero constructor and the following function as a monadic sum:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\text{mplus} \colon A^{?} \to A^{?} \to A^{?} = a_1 \mapsto a_2 \mapsto \begin{cases} \text{Nothing} &amp;amp; \text{if} \ a_1 = \text{Nothing} \and a_2 = \text{Nothing}\\ \text{Just} \, a&#039;_2 &amp;amp; \text{if} \ a_1 = \text{Nothing} \and a_2 = \text{Just} \, a&#039;_2 \\ \text{Just} \, a&#039;_1 &amp;amp; \text{if} \ a_1 = \text{Just} \, a&#039;_1 \end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In fact, the resulting structure is an [[idempotent]] [[monoid]].&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Scala ===&lt;br /&gt;
[[Scala (programming language)|Scala]] implements Option as a parameterized type, so a variable can be an Option, accessed as follows:&amp;lt;ref name=&amp;quot;OderskySpoon2008&amp;quot;&amp;gt;{{cite book|author1=Martin Odersky|author2=Lex Spoon|author3=Bill Venners|title=Programming in Scala|url=http://books.google.com/books?id=MFjNhTjeQKkC&amp;amp;pg=PA283|accessdate=6 September 2011|year=2008|publisher=Artima Inc|isbn=978-0-9815316-0-1|pages=282–284}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;scala&amp;quot;&amp;gt;&lt;br /&gt;
// Defining variables that are Options of type Int&lt;br /&gt;
val res1: Option[Int] = Some(42)&lt;br /&gt;
val res2: Option[Int] = None&lt;br /&gt;
&lt;br /&gt;
// This function uses pattern matching to deconstruct Options&lt;br /&gt;
def compute(opt: Option[Int]) = opt match {&lt;br /&gt;
  case None =&amp;gt; &amp;quot;No value&amp;quot;&lt;br /&gt;
  case Some(x) =&amp;gt; &amp;quot;The value is: &amp;quot; + x&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
System.out.println(compute(res1))  // The value is: 42&lt;br /&gt;
System.out.println(compute(res2))  // No value&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An Option value is usually used with [[pattern matching]], as in the previous example.&lt;br /&gt;
In this way, the program is safe as it cannot generate any exception or error (e.g. by trying to obtain the value of an &amp;lt;code&amp;gt;Option&amp;lt;/code&amp;gt; variable that is equal to &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt;).&lt;br /&gt;
Therefore, it essentially works as a type-safe alternative to the null value.&lt;br /&gt;
&lt;br /&gt;
=== F# ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ocaml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(* This function uses pattern matching to deconstruct Options *)&lt;br /&gt;
let compute = function&lt;br /&gt;
    None   -&amp;gt; &amp;quot;No value&amp;quot;&lt;br /&gt;
  | Some x -&amp;gt; sprintf &amp;quot;The value is: %d&amp;quot; x&lt;br /&gt;
&lt;br /&gt;
printfn &amp;quot;%s&amp;quot; (compute &amp;lt;| Some 42)(* The value is: 42 *)&lt;br /&gt;
printfn &amp;quot;%s&amp;quot; (compute None)      (* No value         *)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Haskell ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;haskell&amp;quot;&amp;gt;&lt;br /&gt;
-- Defining variables that are Maybes of type Int&lt;br /&gt;
res1, res2 :: Maybe Int&lt;br /&gt;
res1 = Just 42&lt;br /&gt;
res2 = Nothing&lt;br /&gt;
&lt;br /&gt;
-- This function uses pattern matching to deconstruct Maybes&lt;br /&gt;
compute :: Maybe Int -&amp;gt; String&lt;br /&gt;
compute may = case may of&lt;br /&gt;
    Nothing -&amp;gt; &amp;quot;No value&amp;quot;&lt;br /&gt;
    Just x  -&amp;gt; &amp;quot;The value is: &amp;quot; ++ show x&lt;br /&gt;
&lt;br /&gt;
main = do&lt;br /&gt;
    print $ compute res1 -- The value is: 42&lt;br /&gt;
    print $ compute res2 -- No value&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Tagged union]]&lt;br /&gt;
* [[Nullable type]]&lt;br /&gt;
* [[Null Object pattern]]&lt;br /&gt;
* [[Sentinel value]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Data types}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Functional programming]]&lt;br /&gt;
[[Category:Data types]]&lt;br /&gt;
[[Category:Type theory]]&lt;/div&gt;</summary>
		<author><name>155.99.204.81</name></author>
	</entry>
</feed>