Elm Exactly
A Standard Definition of Elm?Draft version 0.4 / Appendix D

DThe Initial Dynamic Basis

We indicate components of the initial basis by the subscript 0, as in Appendix C; in this appendix ME0\ME_0, E0E_0 and VE0\VE_0 denote dynamic objects. The initial dynamic basis is the module environment

B0=ME0, B_0=\ME_0 ,

whose domain is the domain of the static ME0\ME_0 (Section C.2). For each modid\modid in that domain, ME0(modid)=(RA,CE,VE)\ME_0(\modid)=(\dmRA,\dmCE,\VE) is a dynamic interface (Section 7.2), given in Section D.2. Every module is evaluated starting from the environment

E0=({},VE0),VE0={[]↦[], ::↦::}, E_0=(\emptymap,\VE_0),\qquad \VE_0=\{\kw{[]}\mapsto\kw{[]},\ \kw{::}\mapsto\kw{::}\},

to which its imports add (Chapter 7), as statically it starts from the environment E0E_0 of Section C.2. E0E_0 is an environment of Chapter 6, with an empty qualified environment; it binds the two list constructor names to the constructor values they name (Section 6.3). Every identifier of the initial static basis is bound in the initial dynamic basis, and the reverse; the hidden identifiers of Section C.2 are bound only in the environments of the texts of Section D.3. The values of the basis are constructor values, special values, closures given by the text of the library elm/core 1.0.5, and basic values, whose meaning is the function APPLY\APPLY of Section D.4. The basic mathematical operations are defined there in full, on the special values defined in Section D.1; every one of them has a result for every argument, a defined value being given even where no mathematically correct one exists. Three things are left to the implementation and recorded in Appendix E: the range of Int with its normalisation, the accuracy of the elementary functions on floats, and the string that Debug.toString gives.

D.1Special Values

The class of special values (Section 6.3) is the disjoint union

SVal=IntRange∪Flt∪Chr∪Str \SVal=\IntRange\cup\effFlt\cup\dbChr\cup\effStr

of the Int values, the floats, the characters and the strings, defined below. The union is disjoint: the Int value 33 and the float 33 are different special values. We write Z\mathbb{Z} for the set of integers and R\mathbb{R} for the set of real numbers.

D.1.1Int Values

The set IntRange⊆Z\IntRange\subseteq\mathbb{Z} of Int values and the normalisation norm:Z→IntRange\norm:\mathbb{Z}\to\IntRange are parameters of the definition. Every implementation chooses them so that:

  • IntRange\IntRange has a least member min⁡IntRange\min\IntRange and a greatest member max⁡IntRange\max\IntRange, and contains every integer between them;

  • min⁡IntRange≤−231\min\IntRange\leq -2^{31} and 231−1≤max⁡IntRange2^{31}-1\leq\max\IntRange;

  • if n∈IntRangen\in\IntRange and n≠min⁡IntRangen\neq\min\IntRange, then −n∈IntRange-n\in\IntRange;

  • norm(n)=n\norm(n)=n for every n∈IntRangen\in\IntRange.

The choices of the implementations are given in Section E.1. Int values are integers, so Int has one zero.

D.1.2Floats

The finite non-zero floats are the real numbers m⋅2qm\cdot 2^{q} and −m⋅2q-m\cdot 2^{q}, where mm and qq are integers with either

252≤m<253 and −1074≤q≤971,or1≤m<252 and q=−1074. 2^{52}\leq m<2^{53}\ \text{and}\ -1074\leq q\leq 971, \quad\text{or}\quad 1\leq m<2^{52}\ \text{and}\ q=-1074 .

Each has exactly one such representation, and mm is its significand. They are the finite non-zero numbers of the binary64 format of the standard IEEE 754-2019. The set of floats is

Flt={finite non-zero floats}∪{+0,−0,+∞,−∞,NaN}, \effFlt=\{\text{finite non-zero floats}\}\cup\{+0,-0,+\infty,-\infty,\dbNaN\},

and Fltfin=Flt∖{+∞,−∞,NaN}\effFltFin=\effFlt\setminus\{+\infty,-\infty,\dbNaN\} is the set of finite floats. The two zeros are different floats, and so are the two infinities. There is one NaN. In this appendix xx, yy and zz range over Flt\effFlt.

In a formula, a float other than NaN stands for the number it denotes on the extended real line, both zeros denoting 00; thus x<yx<y and x=yx=y compare numbers, and +0=−0+0=-0 holds as a comparison of numbers. That xx is a particular float, such as −0-0, is said in words. For x≠NaNx\neq\dbNaN, the sign sgn(x)\dbsgn(x) is +1+1 when xx is +0+0, +∞+\infty or positive, and −1-1 when xx is −0-0, −∞-\infty or negative. For s∈{+1,−1}s\in\{+1,-1\}, s⋅0s\cdot 0 and s⋅∞s\cdot\infty are the zero and the infinity of sign ss, and for a float z≠NaNz\neq\dbNaN, s⋅zs\cdot z is zz when s=+1s=+1 and zz with its sign reversed when s=−1s=-1.

Real numbers are rounded to floats by fl:R→Flt\dbfl:\mathbb{R}\to\effFlt, rounding to nearest with ties to even as IEEE 754-2019 defines it:

  • fl(r)=+∞\dbfl(r)=+\infty if r≥21024−2970r\geq 2^{1024}-2^{970}, and fl(r)=−∞\dbfl(r)=-\infty if r≤−(21024−2970)r\leq -(2^{1024}-2^{970});

  • otherwise, if r≠0r\neq 0, fl(r)\dbfl(r) is the finite float nearest to rr and, of two equally near, the one whose significand is even (a zero counting as even); when that float is a zero, it is the zero of the sign of rr;

  • fl(0)=+0\dbfl(0)=+0.

Every Int value nn with ∣n∣≤253|n|\leq 2^{53} is a float exactly: fl(n)=n\dbfl(n)=n.

D.1.3Characters and Strings

The set Chr\dbChr of characters is a parameter of the definition (Section E.2), with an injective function

code:Chr→IntRange, \dbcode:\dbChr\to\IntRange,

the code of a character, which the basic value Char.toCode gives (Figure 53). For every Unicode scalar value hh there is a character with the code hh, the character with code point hh: it is the character that the escape \u{hh} denotes (Figure 1), and the one that a character constant holding that character itself denotes. A further parameter is a function

other:Z→Chr, \mathit{other}:\mathbb{Z}\to\dbChr,

the character that Char.fromCode gives for an integer that is not a Unicode scalar value. Nothing is required of other\mathit{other}: its result may be a character that is no Unicode scalar value, such as a lone surrogate, but it is a character, and so has a code in IntRange\IntRange distinct from that of every other character. Nothing else is required of characters: the initial basis has no operation on characters other than equality, order, Char.toCode and Char.fromCode. A string is a finite sequence ch1⋯chk\dbch_1\cdots\dbch_k of characters (k≥0k\geq 0), its length being kk; Str\effStr is the set of strings, and ss ranges over Str\effStr. A character constant denotes a character and a string constant a string (Chapter 2).

D.2The Value Environments

Every interface of ME0\ME_0 has RA=∅\dmRA=\emptyset, since the basis has no record alias. The constructor environments are

CEofME0(Basics) = {Bool↦{True↦True, False↦False},{Order↦{LT↦LT, EQ↦EQ, GT↦GT},{Never↦{}},CEofME0(Maybe) = {Maybe↦{Just↦Just, Nothing↦Nothing}},CEofME0(Result) = {Result↦{Ok↦Ok, Err↦Err}}, \begin{array}{ll} \dmCE\of\ME_0(\kw{Basics}) {\ =\ }& \{\kw{Bool}\mapsto\{\kw{True}\mapsto\kw{True},\ \kw{False}\mapsto\kw{False}\},\\ & \phantom{\{}\kw{Order}\mapsto\{\kw{LT}\mapsto\kw{LT},\ \kw{EQ}\mapsto\kw{EQ},\ \kw{GT}\mapsto\kw{GT}\},\\ & \phantom{\{}\kw{Never}\mapsto\emptymap\},\\ \dmCE\of\ME_0(\kw{Maybe}) {\ =\ }& \{\kw{Maybe}\mapsto\{\kw{Just}\mapsto\kw{Just},\ \kw{Nothing}\mapsto\kw{Nothing}\}\},\\ \dmCE\of\ME_0(\kw{Result}) {\ =\ }& \{\kw{Result}\mapsto\{\kw{Ok}\mapsto\kw{Ok},\ \kw{Err}\mapsto\kw{Err}\}\}, \end{array}

and CEofME0(modid)={}\dmCE\of\ME_0(\modid)=\emptymap for every other modid\modid. Thus CE\dmCE maps every custom type that a module of the basis exposes to the constructors it exposes, the closed type Never to the empty map; the abstract types are in the domain of no CE\dmCE. The value environments of the interfaces of ME0\ME_0 are shown in Figures 45 to 47. In the figures, a constructor is bound to the constructor value it names, whose arity is shown. An identifier shown with an arity is bound to the basic value of the same name, which has that arity; we write the basic values of Basics unqualified (add) and those of other modules qualified (Debug.log), and the basic values of Figures 45 to 47 are all distinct. An identifier marked “Elm” is bound to the value of its elm/core text (Section D.3); for abs, to that of its default copy, at Float\tFloat, the copy at Int\tInt being bound to a new variable (Section D.3). The identifiers e and pi are bound to floats.

var or con ↦ varityTrue, False ↦ True, False0LT, EQ, GT ↦ LT, EQ, GT0toFloat, round, floor, ceiling, truncate ↦ basic value1compare ↦ basic value2min, max ↦ basic value2clamp ↦ basic value3not ↦ basic value1xor ↦ basic value2modBy, remainderBy ↦ basic value2negate ↦ basic value1sqrt ↦ basic value1cos, sin, tan, acos, asin, atan ↦ basic value1atan2 ↦ basic value2isNaN, isInfinite ↦ basic value1e ↦ fl(e)pi ↦ fl(π)abs ↦ ElmlogBase, degrees, radians, turns ↦ ElmfromPolar, toPolar ↦ Elmidentity, always, never ↦ Elm \begin{array}{|rclc|} \hline \var\ \text{or}\ \con {\ }& \mapsto {\ }& v {\qquad}& \arity\\ \hline \href{/standard/basis/Basics/Bool}{\kw{True}},\ \href{/standard/basis/Basics/Bool}{\kw{False}} {\ }& \mapsto {\ }& \kw{True},\ \kw{False} {\qquad}& 0\\ \href{/standard/basis/Basics/Order}{\kw{LT}},\ \href{/standard/basis/Basics/Order}{\kw{EQ}},\ \href{/standard/basis/Basics/Order}{\kw{GT}} {\ }& \mapsto {\ }& \kw{LT},\ \kw{EQ},\ \kw{GT} {\qquad}& 0\\ \hline \href{/standard/basis/Basics/toFloat}{\kw{toFloat}},\ \href{/standard/basis/Basics/round}{\kw{round}},\ \href{/standard/basis/Basics/floor}{\kw{floor}},\ \href{/standard/basis/Basics/ceiling}{\kw{ceiling}},\ \href{/standard/basis/Basics/truncate}{\kw{truncate}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \href{/standard/basis/Basics/compare}{\kw{compare}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \href{/standard/basis/Basics/min}{\kw{min}},\ \href{/standard/basis/Basics/max}{\kw{max}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \href{/standard/basis/Basics/clamp}{\kw{clamp}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 3\\ \href{/standard/basis/Basics/not}{\kw{not}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \href{/standard/basis/Basics/xor}{\kw{xor}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \href{/standard/basis/Basics/modBy}{\kw{modBy}},\ \href{/standard/basis/Basics/remainderBy}{\kw{remainderBy}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \href{/standard/basis/Basics/negate}{\kw{negate}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \href{/standard/basis/Basics/sqrt}{\kw{sqrt}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \href{/standard/basis/Basics/cos}{\kw{cos}},\ \href{/standard/basis/Basics/sin}{\kw{sin}},\ \href{/standard/basis/Basics/tan}{\kw{tan}},\ \href{/standard/basis/Basics/acos}{\kw{acos}},\ \href{/standard/basis/Basics/asin}{\kw{asin}},\ \href{/standard/basis/Basics/atan}{\kw{atan}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \href{/standard/basis/Basics/atan2}{\kw{atan2}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \href{/standard/basis/Basics/isNaN}{\kw{isNaN}},\ \href{/standard/basis/Basics/isInfinite}{\kw{isInfinite}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \hline \href{/standard/basis/Basics/e}{\kw{e}} {\ }& \mapsto {\ }& \dbfl(\dbeuler) {\qquad}& \\ \href{/standard/basis/Basics/pi}{\kw{pi}} {\ }& \mapsto {\ }& \dbfl(\dbpinum) {\qquad}& \\ \hline \href{/standard/basis/Basics/abs}{\kw{abs}} {\ }& \mapsto {\ }& \text{Elm} {\qquad}& \\ \href{/standard/basis/Basics/logBase}{\kw{logBase}},\ \href{/standard/basis/Basics/degrees}{\kw{degrees}},\ \href{/standard/basis/Basics/radians}{\kw{radians}},\ \href{/standard/basis/Basics/turns}{\kw{turns}} {\ }& \mapsto {\ }& \text{Elm} {\qquad}& \\ \href{/standard/basis/Basics/fromPolar}{\kw{fromPolar}},\ \href{/standard/basis/Basics/toPolar}{\kw{toPolar}} {\ }& \mapsto {\ }& \text{Elm} {\qquad}& \\ \href{/standard/basis/Basics/identity}{\kw{identity}},\ \href{/standard/basis/Basics/always}{\kw{always}},\ \href{/standard/basis/Basics/never}{\kw{never}} {\ }& \mapsto {\ }& \text{Elm} {\qquad}& \\ \hline \end{array}
Figure 45: Dynamic VE\VE of ME0(Basics)\ME_0(\kw{Basics})

Each operator of the initial basis stands for a hidden variable of Basics or, for ::, the list constructor (Figure 40). The dynamic operator table

OTDYN:Op→finVal \OTdyn : \cls{Op} \finmap \Val

maps each operator of Figure 3 to the value of the identifier it stands for, and is given in Figure 46. The value of an operator is OTDYN(op)\OTdyn(\opv) in every environment: it is looked up in no environment and reached through no interface.

opstands for ↦ OTDYN(op)arity<<, >>composeL, composeR ↦ Elm^pow ↦ basic value2*, /, //mul, fdiv, idiv ↦ basic value2+, -add, sub ↦ basic value2++append ↦ basic value2:::: ↦ ::2==, /=eq, neq ↦ basic value2<, >, <=, >=lt, gt, le, ge ↦ basic value2&&, ||and, or ↦ basic value2|>, <|apR, apL ↦ Elm \begin{array}{|clclc|} \hline \opv {\quad}& \text{stands for} {\ }& \mapsto {\ }& \OTdyn(\opv) {\qquad}& \arity\\ \hline \kw{<<},\ \kw{>>} {\quad}& \href{/standard/basis/Basics/composeL}{\kw{composeL}},\ \href{/standard/basis/Basics/composeR}{\kw{composeR}} {\ }& \mapsto {\ }& \text{Elm} {\qquad}& \\ \kw{\textasciicircum} {\quad}& \href{/standard/basis/Basics/pow}{\kw{pow}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \kw{*},\ \kw{/},\ \kw{//} {\quad}& \href{/standard/basis/Basics/mul}{\kw{mul}},\ \href{/standard/basis/Basics/fdiv}{\kw{fdiv}},\ \href{/standard/basis/Basics/idiv}{\kw{idiv}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \kw{+},\ \kw{-} {\quad}& \href{/standard/basis/Basics/add}{\kw{add}},\ \href{/standard/basis/Basics/sub}{\kw{sub}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \kw{++} {\quad}& \href{/standard/basis/Basics/append}{\kw{append}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \kw{::} {\quad}& \href{/standard/basis/List}{\kw{::}} {\ }& \mapsto {\ }& \kw{::} {\qquad}& 2\\ \kw{==},\ \kw{/=} {\quad}& \href{/standard/basis/Basics/eq}{\kw{eq}},\ \href{/standard/basis/Basics/neq}{\kw{neq}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \kw{<},\ \kw{>},\ \kw{<=},\ \kw{>=} {\quad}& \href{/standard/basis/Basics/lt}{\kw{lt}},\ \href{/standard/basis/Basics/gt}{\kw{gt}},\ \href{/standard/basis/Basics/le}{\kw{le}},\ \href{/standard/basis/Basics/ge}{\kw{ge}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \kw{\&\&},\ \kw{||} {\quad}& \href{/standard/basis/Basics/and}{\kw{and}},\ \href{/standard/basis/Basics/or}{\kw{or}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \kw{|>},\ \kw{<|} {\quad}& \href{/standard/basis/Basics/apR}{\kw{apR}},\ \href{/standard/basis/Basics/apL}{\kw{apL}} {\ }& \mapsto {\ }& \text{Elm} {\qquad}& \\ \hline \end{array}
Figure 46: The Dynamic Operator Table, OTDYN\OTdyn
var or con ↦ varityMaybeJust ↦ Just1Nothing ↦ Nothing0ResultOk, Err ↦ Ok, Err1ChartoCode, fromCode ↦ basic value1Debuglog ↦ basic value2todo, toString ↦ basic value1Platformworker ↦ basic value1Platform.Cmd and Platform.Subnone ↦ Elmbatch ↦ basic value1map ↦ basic value2Tasksucceed, fail ↦ basic value1andThen, onError ↦ basic value2map, map2, map3, map4, map5 ↦ Elmsequence, mapError, perform, attempt ↦ ElmProcessspawn, sleep, kill ↦ basic value1 \begin{array}{|rclc|} \hline \var\ \text{or}\ \con {\ }& \mapsto {\ }& v {\qquad}& \arity\\ \hline \kw{Maybe}&&&\\ \hline \href{/standard/basis/Maybe/Maybe}{\kw{Just}} {\ }& \mapsto {\ }& \kw{Just} {\qquad}& 1\\ \href{/standard/basis/Maybe/Maybe}{\kw{Nothing}} {\ }& \mapsto {\ }& \kw{Nothing} {\qquad}& 0\\ \hline \kw{Result}&&&\\ \hline \href{/standard/basis/Result/Result}{\kw{Ok}},\ \href{/standard/basis/Result/Result}{\kw{Err}} {\ }& \mapsto {\ }& \kw{Ok},\ \kw{Err} {\qquad}& 1\\ \hline \kw{Char}&&&\\ \hline \href{/standard/basis/Char/toCode}{\kw{toCode}},\ \href{/standard/basis/Char/fromCode}{\kw{fromCode}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \hline \kw{Debug}&&&\\ \hline \href{/standard/basis/Debug/log}{\kw{log}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \href{/standard/basis/Debug/todo}{\kw{todo}},\ \href{/standard/basis/Debug/toString}{\kw{toString}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \hline \kw{Platform}&&&\\ \hline \href{/standard/basis/Platform/worker}{\kw{worker}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \hline \kw{Platform.Cmd}\ \text{and}\ \kw{Platform.Sub}&&&\\ \hline \href{/standard/basis/Platform/Cmd/none}{\kw{none}} {\ }& \mapsto {\ }& \text{Elm} {\qquad}& \\ \href{/standard/basis/Platform/Cmd/batch}{\kw{batch}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \href{/standard/basis/Platform/Cmd/map}{\kw{map}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \hline \kw{Task}&&&\\ \hline \href{/standard/basis/Task/succeed}{\kw{succeed}},\ \href{/standard/basis/Task/fail}{\kw{fail}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \href{/standard/basis/Task/andThen}{\kw{andThen}},\ \href{/standard/basis/Task/onError}{\kw{onError}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\ \href{/standard/basis/Task/map}{\kw{map}},\ \href{/standard/basis/Task/map2}{\kw{map2}},\ \href{/standard/basis/Task/map3}{\kw{map3}},\ \href{/standard/basis/Task/map4}{\kw{map4}},\ \href{/standard/basis/Task/map5}{\kw{map5}} {\ }& \mapsto {\ }& \text{Elm} {\qquad}& \\ \href{/standard/basis/Task/sequence}{\kw{sequence}},\ \href{/standard/basis/Task/mapError}{\kw{mapError}},\ \href{/standard/basis/Task/perform}{\kw{perform}},\ \href{/standard/basis/Task/attempt}{\kw{attempt}} {\ }& \mapsto {\ }& \text{Elm} {\qquad}& \\ \hline \kw{Process}&&&\\ \hline \href{/standard/basis/Process/spawn}{\kw{spawn}},\ \href{/standard/basis/Process/sleep}{\kw{sleep}},\ \href{/standard/basis/Process/kill}{\kw{kill}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\ \hline \end{array}
Figure 47: Dynamic VE\VE of the Other Modules of ME0\ME_0

The interfaces of the modules List, Tuple, String, Array, Bytes, Json.Encode, Json.Decode, VirtualDom and Html are (∅,{},{})(\emptyset,\emptymap,\emptymap): these modules are in ME0\ME_0 for their types, which have no dynamic counterpart (the values of Array and Bytes being given in Sections D.4.9 and D.4.10). The interfaces of Char, Platform, Platform.Cmd, Platform.Sub, Task, Process and Debug are (∅,{},VE)(\emptyset,\emptymap,\VE), with VE\VE as in Figure 47. These interfaces have the property of Section 7.2. The basic values Platform.Cmd.batch and Platform.Cmd.map, and their counterparts in Platform.Sub, are written Cmd.batch, Cmd.map, Sub.batch and Sub.map in Chapter 8, after the qualifiers of the default imports.

Besides those of the figures, the class BasVal contains the following basic values, which are bound to no identifier of the basis: the basic value Elm.Kernel.Basics.log of arity 11 (Section D.3); the basic value Task.command of arity 11, to which the environment of the texts of Task binds the hidden variable command (Section D.3), and whose APPLY\APPLY is given in Section 8.6; the basic values Array.fromList and Array.toList of arity 11, which Chapter 8 applies to encode and decode arrays at ports (Section D.4.9); and the values of ports, outport(p,τ)\effoutport(\effp,\tau) and inport(p,τ)\effinport(\effp,\tau), of arity 11 (Section 8.7).

D.3Values Written in Elm

A value of the basis whose definition in elm/core 1.0.5 is written in Elm is defined by that text, except min, max, clamp and negate, which are basic values (below); the other basic values are those whose definition is a reference to the kernel. The texts of the values of Basics marked “Elm” in Figures 45 and 46 are shown in Figure 48, as they stand in the file Basics.elm of elm/core 1.0.5.

abs n =
  if lt n 0 then -n else n

logBase base number =
  fdiv
    (Elm.Kernel.Basics.log number)
    (Elm.Kernel.Basics.log base)

radians angleInRadians =
  angleInRadians

degrees angleInDegrees =
  fdiv (mul angleInDegrees pi) 180

turns angleInTurns =
  mul (mul 2 pi) angleInTurns
fromPolar (radius, theta) =
  ( mul radius (cos theta)
  , mul radius (sin theta)
  )

toPolar ( x, y ) =
  ( sqrt (add (mul x x) (mul y y))
  , atan2 y x
  )

composeL g f x =
  g (f x)

composeR f g x =
  g (f x)

apR x f =
  f x

apL f x =
  f x

identity x =
  x

always a _ =
  a

never (JustOneMore nvr) =
  never nvr
Figure 48: The Values of Basics Written in Elm

Each text of Figure 48 is a declaration dec\dec that, by the derived forms of Appendix A, has the form var = \ atpat -> exp\var\ \kw{=}\ \kw{\textbackslash}\,\atpat\ \kw{->}\ \expm. Let

EK=E0+(QEK,VEK),whereQEK={Elm.Kernel.Basics↦({},{log↦Elm.Kernel.Basics.log}),QEK={Basics↦({},VEK)}, \begin{array}{l} E_{\mathrm{K}}=E_0+(\QE_{\mathrm{K}},\VE_{\mathrm{K}}),\quad\text{where}\\[0.5ex] \QE_{\mathrm{K}}=\{\kw{Elm.Kernel.Basics}\mapsto(\emptymap,\{\kw{log}\mapsto\kw{Elm.Kernel.Basics.log}\}),\\ \phantom{\QE_{\mathrm{K}}=\{}\kw{Basics}\mapsto(\emptymap,\VE_{\mathrm{K}})\}, \end{array}

and VEK\VE_{\mathrm{K}} binds every identifier of Basics that Figures 45 and 46 do not mark “Elm” to the value shown there, the hidden variables of the operators included, and binds the hidden constructor JustOneMore of the closed type Never to the constructor value JustOneMore of arity 11. The qualifier Basics is bound in EKE_{\mathrm{K}} to the environment of the identifiers of Basics that VEK\VE_{\mathrm{K}} binds, so that the long identifiers Basics.True, Basics.False and Basics.negate that the derived forms of Appendix A introduce into these texts (by if and by prefix minus) denote the values True, False and negate of Figure 45; the texts are part of the definition, not of a program, so the rule that a module cannot qualify its own names does not apply to them. No text refers to a value that another text defines. The value bound to var\var in ME0(Basics)\ME_0(\kw{Basics}) is VE(var)\VE(\var), where

EK⊢dec⇒VE \jdg{E_{\mathrm{K}}}{\dec}{\VE}

by rule (90), or, for never, whose declaration is recursive, by rule (91). In each case VE\VE is unique: it binds var\var to a closure. In the text of abs, -n is the derived form Basics.negate n; the text of negate itself is -n, which by that derived form would apply negate to its own argument, so negate is a basic value. min and max are basic values at every comparable type: at floats their APPLY\APPLY is the minimum and maximum of IEEE 754-2019, which their elm/core texts do not give, and at every other comparable type it is the result of those texts (Section D.4.6). clamp is a basic value likewise: at floats its APPLY\APPLY is built on the minimum and maximum of IEEE 754-2019, which its elm/core text does not give, and at Int values it is the result of that text (Sections D.4.2 and D.4.6). Debug.log, Debug.todo and Debug.toString are kernel references in elm/core, and are basic values.

The values of Platform.Cmd, Platform.Sub and Task marked “Elm” in Figure 47 are defined in the same way by their texts in the files Platform/Cmd.elm, Platform/Sub.elm and Task.elm of elm/core 1.0.5. The text of a value of the module modid\modid is evaluated in the environment

Emodid=E0+(QEmodid,VEmodid), E_{\modid}=E_0+(\QE_{\modid},\VE_{\modid}),

where QEmodid\QE_{\modid} binds each qualifier that the texts of modid\modid use to an environment binding the identifiers they write under it, to their values in ME0\ME_0 or, for a further function of elm/core, to the value of its text (below), and VEmodid\VE_{\modid} binds the identifiers of the interfaces of modid\modid and of the modules it imports unqualified (among them the constructors Ok and Err) to their values in ME0\ME_0. The values marked “Elm” are taken in an order in which each text refers only to values already defined: Task.map before Task.perform, and Task.map2 before Task.sequence. For modid=Task\modid=\kw{Task}, VETask\VE_{\kw{Task}} also binds the two hidden identifiers of Task (Section C.2): the variable command to the basic value Task.command, whose APPLY\APPLY is that of Figure 24, and the constructor Perform of the custom type MyCmd to the constructor value Perform, of arity 11. Neither is in ME0(Task)\ME_0(\kw{Task}). The texts of Task.perform and Task.attempt apply command to a value Perform tk\tk, which APPLY\APPLY makes a leaf command of the task manager. Where such a text refers to a further function of elm/core (Task.sequence applies List.foldr), that function is defined by its text likewise, and the kernel function Elm.Kernel.List.cons is the list constructor ::. Chapter 8 states what these texts give (Section 8.6). The texts are specialised over their number variables with the rest of the program (Section 6.2): the copy of abs used at Float\tFloat compares with the float 00, and the constants 180 and 2 in the texts of degrees and turns, whose type is Float\tFloat, denote floats. Of the values of the basis written in Elm, only abs has a type scheme that quantifies a variable of class number\knum (Figure 38); the identifier abs of Figure 45 is bound to its default copy, at Float\tFloat. Besides this, the value environment of ME0(Basics)\ME_0(\kw{Basics}) binds the new variable of the copy of the declaration of abs at Int\tInt that the specialisation makes, to the value of that copy, evaluated in EKE_{\mathrm{K}} as the default copy is. An occurrence of abs at Int\tInt thus finds its copy: qualified, through the qualifier Basics; unqualified, through the default import import Basics exposing (..), whose exposing list gives the whole of that value environment; and through an exposing item abs of an import, which stands for the variable and the new variable of its copy (Section 7.1). So abs -1.5 is the float 1.51.5, and abs (3 // -1) the Int value 33. Thus the order in which a basis function written in Elm applies the functions it is given, for instance List.foldr from the last element of its list, is fixed by its text. Consequences of the texts of Figure 48 that the definitions of Section D.4 make visible are noted there.

D.4The Function APPLY

For a basic value bb of arity nn and values v1,…,vnv_1,\ldots,v_n, APPLY(b,v1⋯vn)\APPLY(b,v_1\cdots v_n) is a finite set of values (Section 6.5); in this section we separate the arguments by commas, writing APPLY(b,v1,…,vn)\APPLY(b,v_1,\ldots,v_n). The set has exactly one member except where stated: it has two members when an equality test reaches two functions (Section D.4.5), and none for Debug.todo (Section D.4.8). In this section mm and nn range over IntRange\IntRange, xx, yy and zz over Flt\effFlt, and ss and s′s' over Str\effStr. The definitions cover every argument that the evaluation of a program that elaborates supplies to bb.

Overloading. The basic values add, sub, mul, pow, negate and clamp act on Int values and on floats; compare, lt, gt, le, ge, min and max on all comparable values; append on strings and on lists; eq and neq on all values. APPLY\APPLY dispatches on the special values it is given: each case is defined below for each kind of argument. Before evaluation a program is specialised over its number variables, so that every integer constant has the type Int\tInt or Float\tFloat, and an integer constant of type Float\tFloat denotes the nearest float (Section 6.2). Hence both arguments of a number operation are Int values or both are floats, the three arguments of clamp are all Int values or all floats, every argument of a basic value of floats is a float, and an Int value never meets a float in equality or order.

D.4.1Int Arithmetic

For real rr, ⌊r⌋\lfloor r\rfloor is the greatest integer at most rr, ⌈r⌉\lceil r\rceil the least integer at least rr, and trunc(r)\dbtrunc(r) is ⌊r⌋\lfloor r\rfloor when r≥0r\geq 0 and ⌈r⌉\lceil r\rceil when r<0r<0. On Int values, APPLY\APPLY is given in Figure 49. An exact result is normalised into IntRange\IntRange; where an operation has no mathematically correct result, the result is 00.

APPLY(add,m,n) = {norm(m+n)}APPLY(sub,m,n) = {norm(m−n)}APPLY(mul,m,n) = {norm(m⋅n)}APPLY(negate,n) = {norm(−n)}APPLY(idiv,m,n) = {norm(trunc(m/n))}if n≠0 = {0}if n=0APPLY(modBy,n,m) = {m−n⋅⌊m/n⌋}if n≠0 = {0}if n=0APPLY(remainderBy,n,m) = {m−n⋅trunc(m/n)}if n≠0 = {0}if n=0APPLY(pow,m,n) = {norm(mn)}if n≥0 = {1}if n<0 and m=1 = {(−1)n}if n<0 and m=−1 = {0}if n<0 and m∉{1,−1} \begin{array}{rcll} \APPLY(\kw{add},m,n) {\ }& = {\ }& \{\norm(m+n)\} {\quad}& \\ \APPLY(\kw{sub},m,n) {\ }& = {\ }& \{\norm(m-n)\} {\quad}& \\ \APPLY(\kw{mul},m,n) {\ }& = {\ }& \{\norm(m\cdot n)\} {\quad}& \\ \APPLY(\kw{negate},n) {\ }& = {\ }& \{\norm(-n)\} {\quad}& \\[1ex] \APPLY(\kw{idiv},m,n) {\ }& = {\ }& \{\norm(\dbtrunc(m/n))\} {\quad}& \text{if}\ n\neq 0\\ {\ }& = {\ }& \{0\} {\quad}& \text{if}\ n=0\\[1ex] \APPLY(\kw{modBy},n,m) {\ }& = {\ }& \{m-n\cdot\lfloor m/n\rfloor\} {\quad}& \text{if}\ n\neq 0\\ {\ }& = {\ }& \{0\} {\quad}& \text{if}\ n=0\\[1ex] \APPLY(\kw{remainderBy},n,m) {\ }& = {\ }& \{m-n\cdot\dbtrunc(m/n)\} {\quad}& \text{if}\ n\neq 0\\ {\ }& = {\ }& \{0\} {\quad}& \text{if}\ n=0\\[1ex] \APPLY(\kw{pow},m,n) {\ }& = {\ }& \{\norm(m^{n})\} {\quad}& \text{if}\ n\geq 0\\ {\ }& = {\ }& \{1\} {\quad}& \text{if}\ n<0\ \text{and}\ m=1\\ {\ }& = {\ }& \{(-1)^{n}\} {\quad}& \text{if}\ n<0\ \text{and}\ m=-1\\ {\ }& = {\ }& \{0\} {\quad}& \text{if}\ n<0\ \text{and}\ m\notin\{1,-1\} \end{array}
Figure 49: APPLY\APPLY on Int Values

In the figure, m0=1m^{0}=1 for every mm, including 00. The first argument of modBy and remainderBy is the divisor: modBy 4 -5 is 33 and remainderBy 4 -5 is −1-1. The following property, which may easily be demonstrated, shows that modBy and remainderBy need no normalisation.

For n≠0n\neq 0, m−n⋅⌊m/n⌋m-n\cdot\lfloor m/n\rfloor is 00 or has the sign of nn, m−n⋅trunc(m/n)m-n\cdot\dbtrunc(m/n) is 00 or has the sign of mm, and both are less than ∣n∣|n| in absolute value; hence both are members of IntRange\IntRange.

Thus 3 // 0, modBy 0 3 and remainderBy 0 3 are all 00, and, at Int\tInt, 1 ^ -1 is 11, (-1) ^ -3 is −1-1 and 2 ^ -1 is 00. The quotient (min⁡IntRange\min\IntRange) // -1 is norm(−min⁡IntRange)\norm(-\min\IntRange). By the text of abs (Figure 48), abs n is norm(∣n∣)\norm(|n|).

D.4.2Floating-Point Arithmetic

On floats, add, sub, mul, fdiv, negate and sqrt are the operations of IEEE 754-2019 on binary64 numbers, rounding to nearest with ties to even; Figure 50 gives them case by case, the first applicable line giving the result.

APPLY(negate,x) = {NaN}if x is NaN = {(−1)⋅x}otherwiseAPPLY(add,x,y) = {NaN}if x or y is NaN,  or {x,y}={+∞,−∞} = {x}if x∈{+∞,−∞} = {y}if y∈{+∞,−∞} = {−0}if x and y are both −0 = {fl(x+y)}otherwiseAPPLY(sub,x,y) = APPLY(add,x,z)where APPLY(negate,y)={z}APPLY(mul,x,y) = {NaN}if x or y is NaN,  or one is a zero and one an infinity = {sgn(x)sgn(y)⋅∞}if x or y is an infinity = {sgn(x)sgn(y)⋅0}if x or y is a zero = {fl(x⋅y)}otherwiseAPPLY(fdiv,x,y) = {NaN}if x or y is NaN,  or both are zeros, or both infinities = {sgn(x)sgn(y)⋅∞}if x is an infinity, or y a zero = {sgn(x)sgn(y)⋅0}if x is a zero, or y an infinity = {fl(x/y)}otherwiseAPPLY(sqrt,x) = {NaN}if x is NaN, or x<0 = {x}if x∈{+0,−0,+∞} = {fl(x)}otherwise \begin{array}{rcll} \APPLY(\kw{negate},x) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\ \text{is}\ \dbNaN\\ {\ }& = {\ }& \{(-1)\cdot x\} {\quad}& \text{otherwise}\\[1ex] \APPLY(\kw{add},x,y) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\ \text{or}\ y\ \text{is}\ \dbNaN,\\ {\ }& {\ }& {\quad}& \text{or}\ \{x,y\}=\{+\infty,-\infty\}\\ {\ }& = {\ }& \{x\} {\quad}& \text{if}\ x\in\{+\infty,-\infty\}\\ {\ }& = {\ }& \{y\} {\quad}& \text{if}\ y\in\{+\infty,-\infty\}\\ {\ }& = {\ }& \{-0\} {\quad}& \text{if}\ x\ \text{and}\ y\ \text{are both}\ -0\\ {\ }& = {\ }& \{\dbfl(x+y)\} {\quad}& \text{otherwise}\\[1ex] \APPLY(\kw{sub},x,y) {\ }& = {\ }& \APPLY(\kw{add},x,z) {\quad}& \text{where}\ \APPLY(\kw{negate},y)=\{z\}\\[1ex] \APPLY(\kw{mul},x,y) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\ \text{or}\ y\ \text{is}\ \dbNaN,\\ {\ }& {\ }& {\quad}& \text{or one is a zero and one an infinity}\\ {\ }& = {\ }& \{\dbsgn(x)\dbsgn(y)\cdot\infty\} {\quad}& \text{if}\ x\ \text{or}\ y\ \text{is an infinity}\\ {\ }& = {\ }& \{\dbsgn(x)\dbsgn(y)\cdot 0\} {\quad}& \text{if}\ x\ \text{or}\ y\ \text{is a zero}\\ {\ }& = {\ }& \{\dbfl(x\cdot y)\} {\quad}& \text{otherwise}\\[1ex] \APPLY(\kw{fdiv},x,y) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\ \text{or}\ y\ \text{is}\ \dbNaN,\\ {\ }& {\ }& {\quad}& \text{or both are zeros, or both infinities}\\ {\ }& = {\ }& \{\dbsgn(x)\dbsgn(y)\cdot\infty\} {\quad}& \text{if}\ x\ \text{is an infinity,}\ \text{or}\ y\ \text{a zero}\\ {\ }& = {\ }& \{\dbsgn(x)\dbsgn(y)\cdot 0\} {\quad}& \text{if}\ x\ \text{is a zero,}\ \text{or}\ y\ \text{an infinity}\\ {\ }& = {\ }& \{\dbfl(x/y)\} {\quad}& \text{otherwise}\\[1ex] \APPLY(\kw{sqrt},x) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\ \text{is}\ \dbNaN,\ \text{or}\ x<0\\ {\ }& = {\ }& \{x\} {\quad}& \text{if}\ x\in\{+0,-0,+\infty\}\\ {\ }& = {\ }& \{\dbfl(\sqrt{x})\} {\quad}& \text{otherwise} \end{array}
APPLY(isNaN,x) = {True}if x is NaN = {False}otherwiseAPPLY(isInfinite,x) = {True}if x∈{+∞,−∞} = {False}otherwise \begin{array}{rcll} \APPLY(\kw{isNaN},x) {\ }& = {\ }& \{\kw{True}\} {\quad}& \text{if}\ x\ \text{is}\ \dbNaN\\ {\ }& = {\ }& \{\kw{False}\} {\quad}& \text{otherwise}\\[1ex] \APPLY(\kw{isInfinite},x) {\ }& = {\ }& \{\kw{True}\} {\quad}& \text{if}\ x\in\{+\infty,-\infty\}\\ {\ }& = {\ }& \{\kw{False}\} {\quad}& \text{otherwise} \end{array}
Figure 50: APPLY\APPLY on Floats: Arithmetic

Thus 1 / 0 is +∞+\infty, 1 / -0 is −∞-\infty, 0 / 0 is NaN, and x - x is +0+0 for every finite x. In the case x<0x<0 of sqrt, xx is not a zero, so sqrt -0 is −0-0. By the text of abs, abs -0 is −0-0 and abs of NaN is NaN, since lt is false for both (Section D.4.6).

At floats, min and max are the operations minimum and maximum of IEEE 754-2019, the first applicable line giving the result:

APPLY(min,x,y) = {NaN}if x or y is NaN = {−0}if x and y are zeros and one of them is −0 = {x}if x≤y = {y}otherwiseAPPLY(max,x,y) = {NaN}if x or y is NaN = {+0}if x and y are zeros and one of them is +0 = {x}if x≥y = {y}otherwise. \begin{array}{rcll} \APPLY(\kw{min},x,y) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\ \text{or}\ y\ \text{is}\ \dbNaN\\ {\ }& = {\ }& \{-0\} {\quad}& \text{if}\ x\ \text{and}\ y\ \text{are zeros and one of them is}\ {-0}\\ {\ }& = {\ }& \{x\} {\quad}& \text{if}\ x\leq y\\ {\ }& = {\ }& \{y\} {\quad}& \text{otherwise}\\[1ex] \APPLY(\kw{max},x,y) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\ \text{or}\ y\ \text{is}\ \dbNaN\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ x\ \text{and}\ y\ \text{are zeros and one of them is}\ {+0}\\ {\ }& = {\ }& \{x\} {\quad}& \text{if}\ x\geq y\\ {\ }& = {\ }& \{y\} {\quad}& \text{otherwise}. \end{array}

These lines apply when both arguments are floats; at the other comparable values APPLY\APPLY takes the cases of Section D.4.6. The case is selected by the arguments, as for lt: the type schemes of min and max quantify a variable of class comparable\kcomp, not number\knum, so number specialisation makes no copy of them (Section 6.2). The result does not depend on the order of the arguments: with nan for 0/0, max nan 1 and max 1 nan are both NaN, max 0 -0 and max -0 0 are +0+0, and min -0 0 and min 0 -0 are −0-0. At floats, clamp is built on these operations:

APPLY(clamp,x,y,z) = APPLY(min,z′,y)  where APPLY(max,z,x)={z′}, \begin{array}{rcll} \APPLY(\kw{clamp},x,y,z) {\ }& = {\ }& \APPLY(\kw{min},z',y) {\quad}&\\ {\ }& {\ }& \quad\text{where}\ \APPLY(\kw{max},z,x)=\{z'\},&\end{array}

when xx, yy and zz are floats; the first argument is the lower bound, the second the upper bound, and clamp lo hi x is min (max x lo) hi. At Int values APPLY\APPLY takes the cases of Section D.4.6; the case is selected by the arguments, as for add. When lo is greater than hi, the result is hi unless an argument is NaN: clamp 10 0 5 is +0+0. A NaN in any argument gives NaN: clamp 0 1 nan, clamp nan 1 0.5 and clamp 0 nan 0.5 are all NaN. Zeros are ordered as by max and min: clamp 0 1 -0 is +0+0, the maximum of −0-0 and +0+0 being +0+0, and clamp -1 -0 0 is −0-0.

D.4.3Powers and Elementary Functions

The power at floats, the trigonometric functions, and the logarithm Elm.Kernel.Basics.log on which logBase is built, denote the real functions xyx^{y}, sin⁡\sin, cos⁡\cos, tan⁡\tan, arcsin⁡\arcsin, arccos⁡\arccos, arctan⁡\arctan, the natural logarithm ln⁡\ln, and the two-argument arctangent, rounded to a float, with the special values that IEEE 754-2019 (Section 9.2) recommends. The two-argument arctangent of a point (x,y)≠(0,0)(x,y)\neq(0,0) is the angle θ\theta with −π<θ≤π-\dbpinum<\theta\leq\dbpinum such that (x,y)=ρ⋅(cos⁡θ,sin⁡θ)(x,y)=\rho\cdot(\cos\theta,\sin\theta) for some ρ>0\rho>0; the first argument of atan2 is yy. The power is given in Figure 51 and the other functions in Figure 52; in each, the first applicable line gives the result. An integer kk is odd when k=2j+1k=2j+1 for an integer jj.

APPLY(pow,x,y) = {1}if y is a zero = {1}if x is 1 = {NaN}if x or y is NaN = {sgn(x)⋅∞}if x is a zero and y<0 an odd integer = {+∞}if x is a zero and y<0 = {x}if x is a zero and y>0 an odd integer = {+0}if x is a zero and y>0 = {1}if x=−1 and y∈{+∞,−∞} = {+0}if ∣x∣<1 and y=+∞ = {+0}if ∣x∣>1 and y=−∞ = {+∞}if ∣x∣>1 and y=+∞ = {+∞}if ∣x∣<1 and y=−∞ = {+0}if x=+∞ and y<0 = {+∞}if x=+∞ and y>0 = {−0}if x=−∞ and y<0 an odd integer = {−∞}if x=−∞ and y>0 an odd integer = {+0}if x=−∞ and y<0 = {+∞}if x=−∞ and y>0 = {NaN}if x<0 and y is not an integer = {fl(xy)}otherwise \begin{array}{rcll} \APPLY(\kw{pow},x,y) {\ }& = {\ }& \{1\} {\quad}& \text{if}\ y\ \text{is a zero}\\ {\ }& = {\ }& \{1\} {\quad}& \text{if}\ x\ \text{is}\ 1\\ {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\ \text{or}\ y\ \text{is}\ \dbNaN\\ {\ }& = {\ }& \{\dbsgn(x)\cdot\infty\} {\quad}& \text{if}\ x\ \text{is a zero and}\ y<0\ \text{an odd integer}\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ x\ \text{is a zero and}\ y<0\\ {\ }& = {\ }& \{x\} {\quad}& \text{if}\ x\ \text{is a zero and}\ y>0\ \text{an odd integer}\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ x\ \text{is a zero and}\ y>0\\ {\ }& = {\ }& \{1\} {\quad}& \text{if}\ x=-1\ \text{and}\ y\in\{+\infty,-\infty\}\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ |x|<1\ \text{and}\ y=+\infty\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ |x|>1\ \text{and}\ y=-\infty\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ |x|>1\ \text{and}\ y=+\infty\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ |x|<1\ \text{and}\ y=-\infty\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ x=+\infty\ \text{and}\ y<0\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ x=+\infty\ \text{and}\ y>0\\ {\ }& = {\ }& \{-0\} {\quad}& \text{if}\ x=-\infty\ \text{and}\ y<0\ \text{an odd integer}\\ {\ }& = {\ }& \{-\infty\} {\quad}& \text{if}\ x=-\infty\ \text{and}\ y>0\ \text{an odd integer}\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ x=-\infty\ \text{and}\ y<0\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ x=-\infty\ \text{and}\ y>0\\ {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x<0\ \text{and}\ y\ \text{is not an integer}\\ {\ }& = {\ }& \{\dbfl(x^{y})\} {\quad}& \text{otherwise} \end{array}
Figure 51: APPLY\APPLY on Floats: Power

The first two lines apply even when the other argument is NaN. In the last line of Figure 51, xx and yy are finite and xx is not a zero; when x<0x<0, yy is an integer and xy=(−1)y∣x∣yx^{y}=(-1)^{y}|x|^{y}. Thus 1 ^ (1/0) is 11, and (-8) ^ (1/3) is NaN.

APPLY(b,NaN) = {NaN}for each b of the figureAPPLY(b,x) = {x}if x is a zero, for b∈{sin,tan,asin,atan}APPLY(b,x) = {NaN}if x∈{+∞,−∞}, for b∈{sin,cos,tan}APPLY(b,x) = {NaN}if ∣x∣>1, for b∈{asin,acos}APPLY(atan,x) = {sgn(x)⋅fl(π/2)}if x∈{+∞,−∞} \begin{array}{rcll} \APPLY(b,\dbNaN) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{for each}\ b\ \text{of the figure}\\[1ex] \APPLY(b,x) {\ }& = {\ }& \{x\} {\quad}& \text{if}\ x\ \text{is a zero, for}\ b\in\{\kw{sin},\kw{tan},\kw{asin},\kw{atan}\}\\ \APPLY(b,x) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\in\{+\infty,-\infty\},\ \text{for}\ b\in\{\kw{sin},\kw{cos},\kw{tan}\}\\ \APPLY(b,x) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ |x|>1,\ \text{for}\ b\in\{\kw{asin},\kw{acos}\}\\ \APPLY(\kw{atan},x) {\ }& = {\ }& \{\dbsgn(x)\cdot\dbfl(\dbpinum/2)\} {\quad}& \text{if}\ x\in\{+\infty,-\infty\} \end{array}
APPLY(Elm.Kernel.Basics.log,x) = {−∞}if x is a zero = {NaN}if x<0 = {+∞}if x=+∞APPLY(b,x) = {fl(f(x))}otherwise, for each b \begin{array}{rcll} \APPLY(\kw{Elm.Kernel.Basics.log},x) {\ }& = {\ }& \{-\infty\} {\quad}& \text{if}\ x\ \text{is a zero}\\ {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x<0\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ x=+\infty\\[1ex] \APPLY(b,x) {\ }& = {\ }& \{\dbfl(f(x))\} {\quad}& \text{otherwise, for each}\ b \end{array}
APPLY(atan2,y,x) = {NaN}if x or y is NaN = {y}if y is a zero, and x is +0 or x>0 = {sgn(y)⋅fl(π)}if y is a zero, and x is −0 or x<0 = {sgn(y)⋅fl(π/2)}if x is a zero = {sgn(y)⋅fl(π/2)}if y is an infinity and x is finite = {sgn(y)⋅fl(3π/4)}if y is an infinity and x=−∞ = {sgn(y)⋅fl(π/4)}if y is an infinity and x=+∞ = {sgn(y)⋅fl(π)}if x=−∞ = {sgn(y)⋅0}if x=+∞ = {fl(θ)}otherwise \begin{array}{rcll} \APPLY(\kw{atan2},y,x) {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\ \text{or}\ y\ \text{is}\ \dbNaN\\ {\ }& = {\ }& \{y\} {\quad}& \text{if}\ y\ \text{is a zero, and}\ x\ \text{is}\ +0\ \text{or}\ x>0\\ {\ }& = {\ }& \{\dbsgn(y)\cdot\dbfl(\dbpinum)\} {\quad}& \text{if}\ y\ \text{is a zero, and}\ x\ \text{is}\ -0\ \text{or}\ x<0\\ {\ }& = {\ }& \{\dbsgn(y)\cdot\dbfl(\dbpinum/2)\} {\quad}& \text{if}\ x\ \text{is a zero}\\ {\ }& = {\ }& \{\dbsgn(y)\cdot\dbfl(\dbpinum/2)\} {\quad}& \text{if}\ y\ \text{is an infinity and}\ x\ \text{is finite}\\ {\ }& = {\ }& \{\dbsgn(y)\cdot\dbfl(3\dbpinum/4)\} {\quad}& \text{if}\ y\ \text{is an infinity and}\ x=-\infty\\ {\ }& = {\ }& \{\dbsgn(y)\cdot\dbfl(\dbpinum/4)\} {\quad}& \text{if}\ y\ \text{is an infinity and}\ x=+\infty\\ {\ }& = {\ }& \{\dbsgn(y)\cdot\dbfl(\dbpinum)\} {\quad}& \text{if}\ x=-\infty\\ {\ }& = {\ }& \{\dbsgn(y)\cdot 0\} {\quad}& \text{if}\ x=+\infty\\ {\ }& = {\ }& \{\dbfl(\theta)\} {\quad}& \text{otherwise} \end{array}
Figure 52: APPLY\APPLY on Floats: Elementary Functions

In the first part of Figure 52, bb ranges over sin, cos, tan, asin, acos, atan and Elm.Kernel.Basics.log, and ff is the real function of bb: sin⁡\sin, cos⁡\cos, tan⁡\tan, arcsin⁡\arcsin, arccos⁡\arccos, arctan⁡\arctan or ln⁡\ln; on the arguments of the line {fl(f(x))}\{\dbfl(f(x))\}, f(x)f(x) is a real number. In the last line for atan2, θ\theta is the two-argument arctangent of (x,y)(x,y). The values e and pi are fl(e)\dbfl(\dbeuler) and fl(π)\dbfl(\dbpinum), and logBase, degrees, radians, turns, fromPolar and toPolar are given by their texts (Figure 48), so that logBase 10 1000 is the quotient of two rounded logarithms, rounded again.

The lines {fl(xy)}\{\dbfl(x^{y})\}, {fl(f(x))}\{\dbfl(f(x))\} and {fl(θ)}\{\dbfl(\theta)\} of Figures 51 and 52 give the correctly rounded result. On those arguments, and only there, the accuracy with which an implementation computes the result is implementation-dependent, and an implementation may give a float near the real result in its place (Section E.3). The operations of Figure 50 allow no such latitude.

D.4.4Conversions

An Int value becomes a float by rounding, and a float becomes an Int value by saturation into IntRange\IntRange:

sat(k)={kif k∈IntRangemax⁡IntRangeif k=+∞ or k>max⁡IntRangemin⁡IntRangeif k=−∞ or k<min⁡IntRange \dbsat(k)=\left\{ \begin{array}{ll} k & \text{if}\ k\in\IntRange\\ \max\IntRange & \text{if}\ k=+\infty\ \text{or}\ k>\max\IntRange\\ \min\IntRange & \text{if}\ k=-\infty\ \text{or}\ k<\min\IntRange \end{array}\right.

for k∈Z∪{+∞,−∞}k\in\mathbb{Z}\cup\{+\infty,-\infty\}. The conversions are given in Figure 53.

APPLY(toFloat,n) = {fl(n)}APPLY(Char.toCode,ch) = {code(ch)}APPLY(Char.fromCode,n) = {ch}if n is a Unicode scalar value  and code(ch)=n = {other(n)}otherwiseAPPLY(round,x) = {sat(⌊x+12⌋)}if x∈FltfinAPPLY(floor,x) = {sat(⌊x⌋)}if x∈FltfinAPPLY(ceiling,x) = {sat(⌈x⌉)}if x∈FltfinAPPLY(truncate,x) = {sat(trunc(x))}if x∈FltfinAPPLY(b,x) = {sat(x)}if x∈{+∞,−∞}APPLY(b,NaN) = {0} \begin{array}{rcll} \APPLY(\kw{toFloat},n) {\ }& = {\ }& \{\dbfl(n)\} {\quad}& \\[1ex] \APPLY(\kw{Char.toCode},\dbch) {\ }& = {\ }& \{\dbcode(\dbch)\} {\quad}& \\ \APPLY(\kw{Char.fromCode},n) {\ }& = {\ }& \{\dbch\} {\quad}& \text{if}\ n\ \text{is a Unicode scalar value}\\ {\ }& {\ }& {\quad}& \text{and}\ \dbcode(\dbch)=n\\ {\ }& = {\ }& \{\mathit{other}(n)\} {\quad}& \text{otherwise}\\[1ex] \APPLY(\kw{round},x) {\ }& = {\ }& \{\dbsat(\lfloor x+\tfrac{1}{2}\rfloor)\} {\quad}& \text{if}\ x\in\effFltFin\\ \APPLY(\kw{floor},x) {\ }& = {\ }& \{\dbsat(\lfloor x\rfloor)\} {\quad}& \text{if}\ x\in\effFltFin\\ \APPLY(\kw{ceiling},x) {\ }& = {\ }& \{\dbsat(\lceil x\rceil)\} {\quad}& \text{if}\ x\in\effFltFin\\ \APPLY(\kw{truncate},x) {\ }& = {\ }& \{\dbsat(\dbtrunc(x))\} {\quad}& \text{if}\ x\in\effFltFin\\[1ex] \APPLY(b,x) {\ }& = {\ }& \{\dbsat(x)\} {\quad}& \text{if}\ x\in\{+\infty,-\infty\}\\ \APPLY(b,\dbNaN) {\ }& = {\ }& \{0\} {\quad}& \end{array}
Figure 53: APPLY\APPLY on Conversions

In the last two lines bb is any of round, floor, ceiling and truncate. The sum x+12x+\frac{1}{2} is exact, not rounded to a float, so round rounds a half upward: round 2.5 is 33 and round -2.5 is −2-2. A float zero of either sign converts to the one Int zero, and toFloat 0 is +0+0, so 1 / toFloat (negate 0) is +∞+\infty.

D.4.5Equality

The function values are the closures, the basic values with their partial applications, and the constructor values awaiting arguments:

Fun=Closure∪BasApp∪{con v1⋯vk∈ConVal∣k<arity(con)}. \dbFun=\Closure\cup\BasApp\cup\{\con\ v_1\cdots v_k\in\ConVal\mid k<\arity(\con)\}.

Equality is structural on all values, and is defined by a set Eq(v,v′)⊆{True,False}\dbEq(v,v')\subseteq\{\kw{True},\kw{False}\} in Figure 54, by recursion on the structure of vv and v′v' (values are finite, and the recursion does not enter a function value). Then

APPLY(eq,v,v′)=Eq(v,v′),APPLY(neq,v,v′)={True∣False∈Eq(v,v′)}∪{False∣True∈Eq(v,v′)}. \begin{array}{rcl} \APPLY(\kw{eq},v,v') &=& \dbEq(v,v'),\\ \APPLY(\kw{neq},v,v') &=& \{\kw{True}\mid\kw{False}\in\dbEq(v,v')\}\\ &&{}\cup\{\kw{False}\mid\kw{True}\in\dbEq(v,v')\}. \end{array}
  1. If v,v′∈Funv,v'\in\dbFun, then Eq(v,v′)={True,False}\dbEq(v,v')=\{\kw{True},\kw{False}\}.

  2. If vv and v′v' are floats: Eq(v,v′)={True}\dbEq(v,v')=\{\kw{True}\} if neither is NaN and v=v′v=v' (so that +0+0 equals −0-0), and {False}\{\kw{False}\} otherwise.

  3. If vv and v′v' are both Int values, both characters, both strings, both the unit value, both process identifiers, or both boundary values (Chapter 8) that are null\effnull, true\efftrue, false\efffalse, numbers, strings or byte sequences: Eq(v,v′)={True}\dbEq(v,v')=\{\kw{True}\} if vv and v′v' are the same, and {False}\{\kw{False}\} otherwise.

  4. If vv and v′v' have the same form, with components v1,…,vkv_1,\ldots,v_k and v1′,…,vk′v'_1,\ldots,v'_k (k≥0k\geq 0), as listed below, then True∈Eq(v,v′)\kw{True}\in\dbEq(v,v') if True∈Eq(vi,vi′)\kw{True}\in\dbEq(v_i,v'_i) for every ii, and False∈Eq(v,v′)\kw{False}\in\dbEq(v,v') if False∈Eq(vi,vi′)\kw{False}\in\dbEq(v_i,v'_i) for some ii. The forms are:

    • tuples with the same number of components;

    • constructor values con v1⋯vk\con\ v_1\cdots v_k and con v1′⋯vk′\con\ v'_1\cdots v'_k with the same constructor name and k=arity(con)k=\arity(\con);

    • records rr and r′r' with Dom r=Dom r′\Dom r=\Dom r', the components being r(lab)r(\lab) and r′(lab)r'(\lab) for each lab∈Dom r\lab\in\Dom r;

    • arrays of boundary values (JSON arrays among them) with the same number of elements, and objects of boundary values with the same set of keys, the components being the values at each key;

    • effect values (Chapter 8) of the same form, with the same primitives, managers and port names, the components being the values, boundary values, tasks, commands and subscriptions they contain.

  5. Otherwise Eq(v,v′)={False}\dbEq(v,v')=\{\kw{False}\}.

Figure 54: Equality of Values

Tested by: ArrayEqualityFlagsTest

The clauses are tried in order. Lists, Maybe and Result values, Bool and Order values, arrays and the values of type Bytes are constructor values, so they are compared by the fourth clause: two lists are equal when they have the same length and equal elements. A record type gives all its records the same domain, so the condition Dom r=Dom r′\Dom r=\Dom r' always holds in a program that elaborates. The following property may easily be demonstrated.

Eq(v,v′)\dbEq(v,v') is non-empty. It is {True,False}\{\kw{True},\kw{False}\} only if, at some depth, corresponding components of vv and v′v' are both function values, and it is {False}\{\kw{False}\} whenever some pair of corresponding components that are not function values is unequal.

Equality is thus deterministic except when the comparison reaches two function values, where it may give either True or False: (\x -> x) == (\x -> x) may evaluate to either. This is the only non-determinism in the dynamic semantics of the Core (rule (84)). Because equality looks only at structure, the identity of values plays no part. NaN is unequal to every float, itself included, so a value with a NaN component is not equal to itself: if t is (0/0, 1), then t == t is False. The two zeros of the floats are equal. Implementations whose equality consults identity are recorded in Section E.4.

D.4.6Order

The comparable values are the Int values, the floats, the characters, the strings, and the lists and tuples whose elements or components are comparable values; they are the values of the types admissible for the class comparable\kcomp (Section 4.4). For comparable values vv and v′v' of one type, cmp(v,v′)∈{LT,EQ,GT}\dbcmp(v,v')\in\{\kw{LT},\kw{EQ},\kw{GT}\} is defined in Figure 55. Then

APPLY(compare,v,v′)={cmp(v,v′)}. \APPLY(\kw{compare},v,v')=\{\dbcmp(v,v')\}.
  1. Int values mm, nn: cmp(m,n)\dbcmp(m,n) is LT if m<nm<n, EQ if m=nm=n, and GT if m>nm>n.

  2. Floats xx, yy: cmp(x,y)\dbcmp(x,y) is EQ if both are NaN, GT if only xx is NaN, LT if only yy is NaN, and otherwise LT, EQ or GT as x<yx<y, x=yx=y or x>yx>y.

  3. Characters: cmp(ch,ch′)=cmp(code(ch),code(ch′))\dbcmp(\dbch,\dbch')=\dbcmp(\dbcode(\dbch),\dbcode(\dbch')).

  4. Strings s=ch1⋯chks=\dbch_1\cdots\dbch_k and s′=ch1′⋯chl′s'=\dbch'_1\cdots\dbch'_l: if chi≠chi′\dbch_i\neq\dbch'_i for some i≤min⁡(k,l)i\leq\min(k,l), and ii is the least such, then cmp(s,s′)=cmp(chi,chi′)\dbcmp(s,s')=\dbcmp(\dbch_i,\dbch'_i); otherwise cmp(s,s′)=cmp(k,l)\dbcmp(s,s')=\dbcmp(k,l).

  5. Lists: cmp([],[])=EQ\dbcmp(\kw{[]},\kw{[]})=\kw{EQ}, cmp([],v1::v2)=LT\dbcmp(\kw{[]},v_1\mathbin{\kw{::}}v_2)=\kw{LT}, cmp(v1::v2,[])=GT\dbcmp(v_1\mathbin{\kw{::}}v_2,\kw{[]})=\kw{GT}, and cmp(v1::v2, v1′::v2′)\dbcmp(v_1\mathbin{\kw{::}}v_2,\,v'_1\mathbin{\kw{::}}v'_2) is cmp(v1,v1′)\dbcmp(v_1,v'_1) if that is not EQ, and cmp(v2,v2′)\dbcmp(v_2,v'_2) otherwise.

  6. Tuples (v1,…,vk)(v_1,\ldots,v_k) and (v1′,…,vk′)(v'_1,\ldots,v'_k): cmp(vi,vi′)\dbcmp(v_i,v'_i) for the least ii with cmp(vi,vi′)≠EQ\dbcmp(v_i,v'_i)\neq\kw{EQ}, and EQ if there is none.

Figure 55: Order of Comparable Values

For comparable values vv, v′v' and v′′v'' of one type, cmp(v,v′)=LT\dbcmp(v,v')=\kw{LT} if and only if cmp(v′,v)=GT\dbcmp(v',v)=\kw{GT}, cmp(v,v)=EQ\dbcmp(v,v)=\kw{EQ}, and if cmp(v,v′)≠GT\dbcmp(v,v')\neq\kw{GT} and cmp(v′,v′′)≠GT\dbcmp(v',v'')\neq\kw{GT} then cmp(v,v′′)≠GT\dbcmp(v,v'')\neq\kw{GT}.

Thus compare is a total order on each comparable type, up to the values it makes EQ, and sorting by it has a defined result. It is EQ for the two zeros and for two NaNs, and puts NaN above every other float; it therefore disagrees with equality at NaN, which is unequal to itself. Characters are ordered by code\dbcode, and strings by their sequences of characters, so the order of one-character strings is that of their characters. The order operators are the IEEE 754 predicates at floats and are derived from cmp\dbcmp at every other comparable type:

APPLY(lt,x,y) = {True}if neither is NaN and x<y = {False}otherwiseAPPLY(le,x,y) = {True}if neither is NaN and x≤y = {False}otherwiseAPPLY(gt,x,y) = APPLY(lt,y,x)APPLY(ge,x,y) = APPLY(le,y,x)APPLY(lt,v,v′) = {True}if cmp(v,v′)=LT = {False}otherwiseAPPLY(le,v,v′) = {True}if cmp(v,v′)≠GT = {False}otherwiseAPPLY(gt,v,v′) = APPLY(lt,v′,v)APPLY(ge,v,v′) = APPLY(le,v′,v) \begin{array}{rcll} \APPLY(\kw{lt},x,y) {\ }& = {\ }& \{\kw{True}\} {\quad}& \text{if neither is NaN and}\ x<y\\ {\ }& = {\ }& \{\kw{False}\} {\quad}& \text{otherwise}\\ \APPLY(\kw{le},x,y) {\ }& = {\ }& \{\kw{True}\} {\quad}& \text{if neither is NaN and}\ x\leq y\\ {\ }& = {\ }& \{\kw{False}\} {\quad}& \text{otherwise}\\ \APPLY(\kw{gt},x,y) {\ }& = {\ }& \APPLY(\kw{lt},y,x) {\quad}& \\ \APPLY(\kw{ge},x,y) {\ }& = {\ }& \APPLY(\kw{le},y,x) {\quad}& \\[1ex] \APPLY(\kw{lt},v,v') {\ }& = {\ }& \{\kw{True}\} {\quad}& \text{if}\ \dbcmp(v,v')=\kw{LT}\\ {\ }& = {\ }& \{\kw{False}\} {\quad}& \text{otherwise}\\ \APPLY(\kw{le},v,v') {\ }& = {\ }& \{\kw{True}\} {\quad}& \text{if}\ \dbcmp(v,v')\neq\kw{GT}\\ {\ }& = {\ }& \{\kw{False}\} {\quad}& \text{otherwise}\\ \APPLY(\kw{gt},v,v') {\ }& = {\ }& \APPLY(\kw{lt},v',v) {\quad}& \\ \APPLY(\kw{ge},v,v') {\ }& = {\ }& \APPLY(\kw{le},v',v) {\quad}& \end{array}

where in the first six lines xx and yy are floats, and in the last six vv and v′v' are comparable values of any other kind. Hence nan < 1, nan > 1 and nan >= nan are False, where nan is 0/0, while [ nan ] > [ 1 ] is True, the list being compared by cmp\dbcmp. At comparable values other than floats, min and max give the results of their elm/core texts, min x y = if lt x y then x else y and max x y = if gt x y then x else y:

APPLY(min,v,v′) = {v}if cmp(v,v′)=LT = {v′}otherwiseAPPLY(max,v,v′) = {v}if cmp(v,v′)=GT = {v′}otherwise, \begin{array}{rcll} \APPLY(\kw{min},v,v') {\ }& = {\ }& \{v\} {\quad}& \text{if}\ \dbcmp(v,v')=\kw{LT}\\ {\ }& = {\ }& \{v'\} {\quad}& \text{otherwise}\\ \APPLY(\kw{max},v,v') {\ }& = {\ }& \{v\} {\quad}& \text{if}\ \dbcmp(v,v')=\kw{GT}\\ {\ }& = {\ }& \{v'\} {\quad}& \text{otherwise}, \end{array}

where vv and v′v' are comparable values that are not floats; the cases at floats are those of Section D.4.2. Thus max [ nan ] [ 1 ] and max [ 1 ] [ nan ] are both [ nan ], the lists being compared by cmp\dbcmp, which puts NaN above every other float. At Int values, clamp gives the result of its elm/core text,

clamp low high number =if lt number low then lowelse if gt number high then high else number, \begin{array}{l} \kw{clamp low high number =}\\ \quad\kw{if lt number low then low}\\ \quad\kw{else if gt number high then high else number}, \end{array}

the first applicable line giving the result:

APPLY(clamp,v,v′,v′′) = {v}if APPLY(lt,v′′,v)={True} = {v′}if APPLY(gt,v′′,v′)={True} = {v′′}otherwise, \begin{array}{rcll} \APPLY(\kw{clamp},v,v',v'') {\ }& = {\ }& \{v\} {\quad}& \text{if}\ \APPLY(\kw{lt},v'',v)=\{\kw{True}\}\\ {\ }& = {\ }& \{v'\} {\quad}& \text{if}\ \APPLY(\kw{gt},v'',v')=\{\kw{True}\}\\ {\ }& = {\ }& \{v''\} {\quad}& \text{otherwise}, \end{array}

where vv, v′v' and v′′v'' are not floats, and are therefore Int values, the type scheme of clamp quantifying a variable of class number\knum; the case at floats is that of Section D.4.2. When lo is greater than hi, clamp lo hi x at Int values is lo if x < lo, else hi if x > hi, else x: clamp 10 0 5 is 1010, where at floats it is +0+0.

D.4.7Booleans, Appending and Functions

The Boolean values are the constructor values True and False.

APPLY(not,v) = {False}if v=True = {True}otherwiseAPPLY(and,v,v′) = {True}if v=v′=True = {False}otherwiseAPPLY(or,v,v′) = {False}if v=v′=False = {True}otherwiseAPPLY(xor,v,v′) = {True}if v≠v′ = {False}otherwise \begin{array}{rcll} \APPLY(\kw{not},v) {\ }& = {\ }& \{\kw{False}\} {\quad}& \text{if}\ v=\kw{True}\\ {\ }& = {\ }& \{\kw{True}\} {\quad}& \text{otherwise}\\ \APPLY(\kw{and},v,v') {\ }& = {\ }& \{\kw{True}\} {\quad}& \text{if}\ v=v'=\kw{True}\\ {\ }& = {\ }& \{\kw{False}\} {\quad}& \text{otherwise}\\ \APPLY(\kw{or},v,v') {\ }& = {\ }& \{\kw{False}\} {\quad}& \text{if}\ v=v'=\kw{False}\\ {\ }& = {\ }& \{\kw{True}\} {\quad}& \text{otherwise}\\ \APPLY(\kw{xor},v,v') {\ }& = {\ }& \{\kw{True}\} {\quad}& \text{if}\ v\neq v'\\ {\ }& = {\ }& \{\kw{False}\} {\quad}& \text{otherwise} \end{array}

The basic values and and or receive both arguments as values, so the operator values (&&) and (||) are strict; only the infixed forms e1 && e2 and e1 || e2, which are derived forms, evaluate their second operand conditionally. The basic value append concatenates strings and lists; for strings, s s′s\,s' is the sequence of the characters of ss followed by those of s′s':

APPLY(append,s,s′) = {s s′}APPLY(append,[],v) = {v}APPLY(append,v1::v2,v) = {v1::v′} \begin{array}{rcl} \APPLY(\kw{append},s,s') {\ }& = {\ }& \{s\,s'\}\\ \APPLY(\kw{append},\kw{[]},v) {\ }& = {\ }& \{v\}\\ \APPLY(\kw{append},v_1\mathbin{\kw{::}}v_2,v) {\ }& = {\ }& \{v_1\mathbin{\kw{::}}v'\} \end{array}

where, in the last line, APPLY(append,v2,v)={v′}\APPLY(\kw{append},v_2,v)=\{v'\}. The composition and application operators and identity, always and never are given by their texts (Figure 48). No value has the type Never, so never is never applied.

D.4.8Debugging

APPLY(Debug.log,s,v) = {v}APPLY(Debug.todo,s) = ∅APPLY(Debug.toString,v) = {sv} \begin{array}{rcl} \APPLY(\kw{Debug.log},s,v) {\ }& = {\ }& \{v\}\\ \APPLY(\kw{Debug.todo},s) {\ }& = {\ }& \emptyset\\ \APPLY(\kw{Debug.toString},v) {\ }& = {\ }& \{s_v\} \end{array}

where svs_v is the string that the implementation gives for vv. Thus Debug.log returns its second argument; any output it makes lies outside the definition. Debug.todo has no result, so an application of it has no value (Section 6.5). The string of Debug.toString is determined by its argument, in a way that is implementation-dependent (Section E.6).

D.4.9Arrays

We take the class Con to contain, besides [] and ::, a third constructor name array\dbarr that no identifier spells, with arity(array)=1\arity(\dbarr)=1. The values of the type Array are the constructor values array v\dbarr\ v with vv a list: the array of the elements of vv, in order. The two basic values that Chapter 8 applies to arrays are

APPLY(Array.fromList,v) = {array v},APPLY(Array.toList,array v) = {v}. \begin{array}{rcl} \APPLY(\kw{Array.fromList},v) {\ }& = {\ }& \{\dbarr\ v\},\\ \APPLY(\kw{Array.toList},\dbarr\ v) {\ }& = {\ }& \{v\}. \end{array}

Two arrays are equal when their lists are, by the fourth clause of Figure 54. The other functions of the library module Array lie outside the definition (Appendix C).

D.4.10Bytes

We take the class Con to contain also a fourth constructor name binary\dbbin that no identifier spells, with arity(binary)=1\arity(\dbbin)=1. The values of the type Bytes are the constructor values binary v\dbbin\ v with vv a list of Int values each from 00 to 255255; the value binary [o1,…,ok]\dbbin\,[o_1,\ldots,o_k] is the finite sequence of the bytes o1,…,oko_1,\ldots,o_k, in order. Two values of type Bytes are equal exactly when their sequences are, by the fourth clause of Figure 54: equality on them is structural, like that on lists. The values of Bytes meet the definition only at ports and in flags, where Chapter 8 relates them to the byte sequences of the boundary (Section 8.7); the functions of the library elm/bytes lie outside the definition (Appendix C).

D.4.11Effect Values

For the basic values of Task, Process, Platform.Cmd, Platform.Sub and Platform, and for Task.command, APPLY\APPLY and the arities are given in Figure 24 (Section 8.6); for the values of ports, outport(p,τ)\effoutport(\effp,\tau) and inport(p,τ)\effinport(\effp,\tau), in Section 8.7.

Discussions

Discuss this chapter·Search the discussions on GitHub

Discussions are on GitHub; one about this chapter has [ch:appendix-dynamic-basis] in its title.

A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.