We indicate components of the initial basis by the subscript 0, as in Appendix C; in this appendix ME0, E0 and VE0 denote dynamic objects. The initial dynamic basis is the module environment
B0=ME0,
whose domain is the domain of the static ME0 (Section C.2). For each modid in that domain, ME0(modid)=(RA,CE,VE) is a dynamic interface (Section 7.2), given in Section D.2. Every module is evaluated starting from the environment
E0=({},VE0),VE0={[]↦[],::↦::},
to which its imports add (Chapter 7), as statically it starts from the environment E0 of Section C.2. E0 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 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.
The class of special values (Section 6.3) is the disjoint union
SVal=IntRange∪Flt∪Chr∪Str
of the Int values, the floats, the characters and the strings, defined below. The union is disjoint: the Int value 3 and the float 3 are different special values. We write Z for the set of integers and R for the set of real numbers.
The finite non-zero floats are the real numbers m⋅2q and −m⋅2q, where m and q are integers with either
252≤m<253and−1074≤q≤971,or1≤m<252andq=−1074.
Each has exactly one such representation, and m 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},
and Fltfin=Flt∖{+∞,−∞,NaN} 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 x, y and z range over Flt.
In a formula, a float other than NaN stands for the number it denotes on the extended real line, both zeros denoting 0; thus x<y and x=y compare numbers, and +0=−0 holds as a comparison of numbers. That xis a particular float, such as −0, is said in words. For x=NaN, the signsgn(x) is +1 when x is +0, +∞ or positive, and −1 when x is −0, −∞ or negative. For s∈{+1,−1}, s⋅0 and s⋅∞ are the zero and the infinity of sign s, and for a float z=NaN, s⋅z is z when s=+1 and z with its sign reversed when s=−1.
Real numbers are rounded to floats by fl:R→Flt, rounding to nearest with ties to even as IEEE 754-2019 defines it:
fl(r)=+∞ if r≥21024−2970, and fl(r)=−∞ if r≤−(21024−2970);
otherwise, if r=0, fl(r) is the finite float nearest to r 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 r;
fl(0)=+0.
Every Int value n with ∣n∣≤253 is a float exactly: fl(n)=n.
The set Chr of characters is a parameter of the definition (Section E.2), with an injective function
code:Chr→IntRange,
the code of a character, which the basic value Char.toCode gives (Figure 53). For every Unicode scalar value h there is a character with the code h, the character with code point h: it is the character that the escape \u{h} denotes (Figure 1), and the one that a character constant holding that character itself denotes. A further parameter is a function
other:Z→Chr,
the character that Char.fromCode gives for an integer that is not a Unicode scalar value. Nothing is required of 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 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 of characters (k≥0), its length being k; Str is the set of strings, and s ranges over Str. A character constant denotes a character and a string constant a string (Chapter 2).
and CEofME0(modid)={} for every other modid. Thus CE 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. The value environments of the interfaces of ME0 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, the copy at Int being bound to a new variable (Section D.3). The identifiers e and pi are bound to floats.
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:OpfinVal
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) in every environment: it is looked up in no environment and reached through no interface.
Figure 47: Dynamic VE of the Other Modules of ME0
The interfaces of the modules List, Tuple, String, Array, Bytes, Json.Encode, Json.Decode, VirtualDom and Html are (∅,{},{}): these modules are in ME0 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), with 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 1 (Section D.3); the basic value Task.command of arity 1, to which the environment of the texts of Task binds the hidden variable command (Section D.3), and whose APPLY is given in Section 8.6; the basic values Array.fromList and Array.toList of arity 1, which Chapter 8 applies to encode and decode arrays at ports (Section D.4.9); and the values of ports, outport(p,τ) and inport(p,τ), of arity 1 (Section 8.7).
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
and VEK 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 1. The qualifier Basics is bound in EK to the environment of the identifiers of Basics that VEK 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 in ME0(Basics) is VE(var), where
EK⊢dec⇒VE
by rule (90), or, for never, whose declaration is recursive, by rule (91). In each case VE is unique: it binds 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 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 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 is evaluated in the environment
Emodid=E0+(QEmodid,VEmodid),
where QEmodid binds each qualifier that the texts of modid use to an environment binding the identifiers they write under it, to their values in ME0 or, for a further function of elm/core, to the value of its text (below), and VEmodid binds the identifiers of the interfaces of modid and of the modules it imports unqualified (among them the constructors Ok and Err) to their values in ME0. 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, VETask also binds the two hidden identifiers of Task (Section C.2): the variable command to the basic value Task.command, whose APPLY is that of Figure 24, and the constructor Perform of the custom type MyCmd to the constructor value Perform, of arity 1. Neither is in ME0(Task). The texts of Task.perform and Task.attempt apply command to a value Performtk, which 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 compares with the float 0, and the constants 180 and 2 in the texts of degrees and turns, whose type is Float, denote floats. Of the values of the basis written in Elm, only abs has a type scheme that quantifies a variable of class number (Figure 38); the identifier abs of Figure 45 is bound to its default copy, at Float. Besides this, the value environment of ME0(Basics) binds the new variable of the copy of the declaration of abs at Int that the specialisation makes, to the value of that copy, evaluated in EK as the default copy is. An occurrence of abs at Int 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.5, and abs (3 // -1) the Int value 3. 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.
For a basic value b of arity n and values v1,…,vn, APPLY(b,v1⋯vn) is a finite set of values (Section 6.5); in this section we separate the arguments by commas, writing APPLY(b,v1,…,vn). 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 m and n range over IntRange, x, y and z over Flt, and s and s′ over Str. The definitions cover every argument that the evaluation of a program that elaborates supplies to b.
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 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 or Float, and an integer constant of type Float 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.
For real r, ⌊r⌋ is the greatest integer at most r, ⌈r⌉ the least integer at least r, and trunc(r) is ⌊r⌋ when r≥0 and ⌈r⌉ when r<0. On Int values, APPLY is given in Figure 49. An exact result is normalised into IntRange; where an operation has no mathematically correct result, the result is 0.
In the figure, m0=1 for every m, including 0. The first argument of modBy and remainderBy is the divisor: modBy 4 -5 is 3 and remainderBy 4 -5 is −1. The following property, which may easily be demonstrated, shows that modBy and remainderBy need no normalisation.
For n=0, m−n⋅⌊m/n⌋ is 0 or has the sign of n, m−n⋅trunc(m/n) is 0 or has the sign of m, and both are less than ∣n∣ in absolute value; hence both are members of IntRange.
Thus 3 // 0, modBy 0 3 and remainderBy 0 3 are all 0, and, at Int, 1 ^ -1 is 1, (-1) ^ -3 is −1 and 2 ^ -1 is 0. The quotient (minIntRange) // -1 is norm(−minIntRange). By the text of abs (Figure 48), abs n is norm(∣n∣).
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)APPLY(add,x,y)APPLY(sub,x,y)APPLY(mul,x,y)APPLY(fdiv,x,y)APPLY(sqrt,x)==================={NaN}{(−1)⋅x}{NaN}{x}{y}{−0}{fl(x+y)}APPLY(add,x,z){NaN}{sgn(x)sgn(y)⋅∞}{sgn(x)sgn(y)⋅0}{fl(x⋅y)}{NaN}{sgn(x)sgn(y)⋅∞}{sgn(x)sgn(y)⋅0}{fl(x/y)}{NaN}{x}{fl(x)}ifxisNaNotherwiseifxoryisNaN,or{x,y}={+∞,−∞}ifx∈{+∞,−∞}ify∈{+∞,−∞}ifxandyare both−0otherwisewhereAPPLY(negate,y)={z}ifxoryisNaN,or one is a zero and one an infinityifxoryis an infinityifxoryis a zerootherwiseifxoryisNaN,or both are zeros, or both infinitiesifxis an infinity,orya zeroifxis a zero,oryan infinityotherwiseifxisNaN,orx<0ifx∈{+0,−0,+∞}otherwise
Thus 1 / 0 is +∞, 1 / -0 is −∞, 0 / 0 is NaN, and x - x is +0 for every finite x. In the case x<0 of sqrt, x is not a zero, so sqrt -0 is −0. By the text of abs, abs -0 is −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)APPLY(max,x,y)========{NaN}{−0}{x}{y}{NaN}{+0}{x}{y}ifxoryisNaNifxandyare zeros and one of them is−0ifx≤yotherwiseifxoryisNaNifxandyare zeros and one of them is+0ifx≥yotherwise.
These lines apply when both arguments are floats; at the other comparable values 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, not number, 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, and min -0 0 and min 0 -0 are −0. At floats, clamp is built on these operations:
when x, y and z 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 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. 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, the maximum of −0 and +0 being +0, and clamp -1 -0 0 is −0.
The power at floats, the trigonometric functions, and the logarithm Elm.Kernel.Basics.log on which logBase is built, denote the real functions xy, sin, cos, tan, arcsin, arccos, arctan, the natural logarithm 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) is the angle θ with −π<θ≤π such that (x,y)=ρ⋅(cosθ,sinθ) for some ρ>0; the first argument of atan2 is y. 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 k is odd when k=2j+1 for an integer j.
APPLY(pow,x,y)===================={1}{1}{NaN}{sgn(x)⋅∞}{+∞}{x}{+0}{1}{+0}{+0}{+∞}{+∞}{+0}{+∞}{−0}{−∞}{+0}{+∞}{NaN}{fl(xy)}ifyis a zeroifxis1ifxoryisNaNifxis a zero andy<0an odd integerifxis a zero andy<0ifxis a zero andy>0an odd integerifxis a zero andy>0ifx=−1andy∈{+∞,−∞}if∣x∣<1andy=+∞if∣x∣>1andy=−∞if∣x∣>1andy=+∞if∣x∣<1andy=−∞ifx=+∞andy<0ifx=+∞andy>0ifx=−∞andy<0an odd integerifx=−∞andy>0an odd integerifx=−∞andy<0ifx=−∞andy>0ifx<0andyis not an integerotherwise
The first two lines apply even when the other argument is NaN. In the last line of Figure 51, x and y are finite and x is not a zero; when x<0, y is an integer and xy=(−1)y∣x∣y. Thus 1 ^ (1/0) is 1, and (-8) ^ (1/3) is NaN.
APPLY(b,NaN)APPLY(b,x)APPLY(b,x)APPLY(b,x)APPLY(atan,x)====={NaN}{x}{NaN}{NaN}{sgn(x)⋅fl(π/2)}for eachbof the figureifxis a zero, forb∈{sin,tan,asin,atan}ifx∈{+∞,−∞},forb∈{sin,cos,tan}if∣x∣>1,forb∈{asin,acos}ifx∈{+∞,−∞}
APPLY(Elm.Kernel.Basics.log,x)APPLY(b,x)===={−∞}{NaN}{+∞}{fl(f(x))}ifxis a zeroifx<0ifx=+∞otherwise, for eachb
APPLY(atan2,y,x)=========={NaN}{y}{sgn(y)⋅fl(π)}{sgn(y)⋅fl(π/2)}{sgn(y)⋅fl(π/2)}{sgn(y)⋅fl(3π/4)}{sgn(y)⋅fl(π/4)}{sgn(y)⋅fl(π)}{sgn(y)⋅0}{fl(θ)}ifxoryisNaNifyis a zero, andxis+0orx>0ifyis a zero, andxis−0orx<0ifxis a zeroifyis an infinity andxis finiteifyis an infinity andx=−∞ifyis an infinity andx=+∞ifx=−∞ifx=+∞otherwise
In the first part of Figure 52, b ranges over sin, cos, tan, asin, acos, atan and Elm.Kernel.Basics.log, and f is the real function of b: sin, cos, tan, arcsin, arccos, arctan or ln; on the arguments of the line {fl(f(x))}, f(x) is a real number. In the last line for atan2, θ is the two-argument arctangent of (x,y). The values e and pi are fl(e) and fl(π), 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)}, {fl(f(x))} and {fl(θ)} 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.
for k∈Z∪{+∞,−∞}. The conversions are given in Figure 53.
APPLY(toFloat,n)APPLY(Char.toCode,ch)APPLY(Char.fromCode,n)APPLY(round,x)APPLY(floor,x)APPLY(ceiling,x)APPLY(truncate,x)APPLY(b,x)APPLY(b,NaN)=========={fl(n)}{code(ch)}{ch}{other(n)}{sat(⌊x+21⌋)}{sat(⌊x⌋)}{sat(⌈x⌉)}{sat(trunc(x))}{sat(x)}{0}ifnis a Unicode scalar valueandcode(ch)=notherwiseifx∈Fltfinifx∈Fltfinifx∈Fltfinifx∈Fltfinifx∈{+∞,−∞}
In the last two lines b is any of round, floor, ceiling and truncate. The sum x+21 is exact, not rounded to a float, so round rounds a half upward: round 2.5 is 3 and round -2.5 is −2. A float zero of either sign converts to the one Int zero, and toFloat 0 is +0, so 1 / toFloat (negate 0) is +∞.
Equality is structural on all values, and is defined by a set Eq(v,v′)⊆{True,False} in Figure 54, by recursion on the structure of v and v′ (values are finite, and the recursion does not enter a function value). Then
If v and v′ are floats: Eq(v,v′)={True} if neither is NaN and v=v′ (so that +0 equals −0), and {False} otherwise.
If v and 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, true, false, numbers, strings or byte sequences: Eq(v,v′)={True} if v and v′ are the same, and {False} otherwise.
If v and v′ have the same form, with components v1,…,vk and v1′,…,vk′ (k≥0), as listed below, then True∈Eq(v,v′) if True∈Eq(vi,vi′) for every i, and False∈Eq(v,v′) if False∈Eq(vi,vi′) for some i. The forms are:
tuples with the same number of components;
constructor values conv1⋯vk and conv1′⋯vk′ with the same constructor name and k=arity(con);
records r and r′ with Domr=Domr′, the components being r(lab) and r′(lab) for each lab∈Domr;
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.
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 Domr=Domr′ always holds in a program that elaborates. The following property may easily be demonstrated.
Eq(v,v′) is non-empty. It is {True,False} only if, at some depth, corresponding components of v and v′ are both function values, and it is {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.
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 (Section 4.4). For comparable values v and v′ of one type, cmp(v,v′)∈{LT,EQ,GT} is defined in Figure 55. Then
APPLY(compare,v,v′)={cmp(v,v′)}.
Int values m, n: cmp(m,n) is LT if m<n, EQ if m=n, and GT if m>n.
Floats x, y: cmp(x,y) is EQ if both are NaN, GT if only x is NaN, LT if only y is NaN, and otherwise LT, EQ or GT as x<y, x=y or x>y.
Characters: cmp(ch,ch′)=cmp(code(ch),code(ch′)).
Strings s=ch1⋯chk and s′=ch1′⋯chl′: if chi=chi′ for some i≤min(k,l), and i is the least such, then cmp(s,s′)=cmp(chi,chi′); otherwise cmp(s,s′)=cmp(k,l).
Lists: cmp([],[])=EQ, cmp([],v1::v2)=LT, cmp(v1::v2,[])=GT, and cmp(v1::v2,v1′::v2′) is cmp(v1,v1′) if that is not EQ, and cmp(v2,v2′) otherwise.
Tuples (v1,…,vk) and (v1′,…,vk′): cmp(vi,vi′) for the least i with cmp(vi,vi′)=EQ, and EQ if there is none.
For comparable values v, v′ and v′′ of one type, cmp(v,v′)=LT if and only if cmp(v′,v)=GT, cmp(v,v)=EQ, and if cmp(v,v′)=GT and cmp(v′,v′′)=GT then cmp(v,v′′)=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, 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 at every other comparable type:
APPLY(lt,x,y)APPLY(le,x,y)APPLY(gt,x,y)APPLY(ge,x,y)APPLY(lt,v,v′)APPLY(le,v,v′)APPLY(gt,v,v′)APPLY(ge,v,v′)============{True}{False}{True}{False}APPLY(lt,y,x)APPLY(le,y,x){True}{False}{True}{False}APPLY(lt,v′,v)APPLY(le,v′,v)if neither is NaN andx<yotherwiseif neither is NaN andx≤yotherwiseifcmp(v,v′)=LTotherwiseifcmp(v,v′)=GTotherwise
where in the first six lines x and y are floats, and in the last six v and 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. 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:
where v and 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, 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,
where v, v′ and v′′ are not floats, and are therefore Int values, the type scheme of clamp quantifying a variable of class number; 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 10, where at floats it is +0.
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, ss′ is the sequence of the characters of s followed by those of s′:
where, in the last line, APPLY(append,v2,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.
where sv is the string that the implementation gives for v. 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).
We take the class Con to contain, besides [] and ::, a third constructor name array that no identifier spells, with arity(array)=1. The values of the type Array are the constructor values arrayv with v a list: the array of the elements of v, in order. The two basic values that Chapter 8 applies to arrays are
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).
We take the class Con to contain also a fourth constructor name binary that no identifier spells, with arity(binary)=1. The values of the type Bytes are the constructor values binaryv with v a list of Int values each from 0 to 255; the value binary[o1,…,ok] is the finite sequence of the bytes o1,…,ok, 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).
For the basic values of Task, Process, Platform.Cmd, Platform.Sub and Platform, and for Task.command, APPLY and the arities are given in Figure 24 (Section 8.6); for the values of ports, outport(p,τ) and inport(p,τ), in Section 8.7.