Elm Exactly

Rule 1s-atexp-scon

Atomic ExpressionsC⊢atexp⇒τ\jdg{C}{\atexp}{\tau}
type(scon)≻τC⊢scon⇒τ\frac{\begin{array}{c}\typeof(\scon) \succ \tau\end{array}}{\begin{array}{c}\jdg{C}{\scon}{\tau}\end{array}}
(1)
Read it in its chapter·Permanent address: /standard/rules/s-atexp-scon

Comments

For an integer constant, τ\tau may be any type in Admnumber\Adm{\knum}: Int\tInt, Float\tFloat or a type variable of class number\knum. A floating point, character or string constant has exactly its type. The type that counts for evaluation is the one the principal derivation gives (Section 4.10); where it is a variable that nothing binds, number specialisation takes it to be Float\tFloat (Section 6.2).

Referred to from

TeX source
\defnrule[r:s-atexp-scon]
  {\typeof(\scon) \succ \tau}
  {\jdg{C}{\scon}{\tau}}

Tests (73)

  • elm / DebugNumberAtFloatTest
    Unannotated functions over the `number` type that use `Debug.toString` and `Debug.log` give the right results when called with a `Float` and with an `Int` in the same program.
  • elm / LetDestructNestedSingleConstructorNumberTest
    A `let` destructuring pattern through two nested single-constructor types reads a number literal that is then used as a Float.
  • elm / LetNumberAndThenTest
    An unannotated `let` binding `Just 30`, whose literal has the constrained type `number`, is used at `Float` inside `Maybe.andThen`: `round (30 * 1.5)` gives 45.
  • elm / LetNumberApplyToTest
    An unannotated `let`-bound number literal reaches a Float multiplication only through a generic higher-order function: `round (applyTo (\x -> x * 1.5) n)` with `n = 30` gives 45.
  • elm / LetNumberAsPatternTest
    A tuple of number literals matched with an `as` pattern, where one part and the whole tuple are both used.
  • elm / LetNumberBoxedSilentMiscompileTest
    Number literals placed inside a container by an unannotated `let` binding, then taken out and used as Floats, give the correct Float results.
  • elm / LetNumberCaseLetTest
    An unannotated number literal bound by a `let` inside a `case` branch, then used as a Float: `round (30 * 1.5)` gives 45.
  • elm / LetNumberCaseTuple3Test
    A triple of number literals destructured by `case` twice, once summed as Ints and once as Floats.
  • elm / LetNumberClosureInRecordTest
    An anonymous function that uses an unannotated `let`-bound number is stored in a record field and then called with a Float: `rec.f 1.5` computes `1.5 * 30`, logged rounded as 45.
  • elm / LetNumberDeepNestRecordTest
    A `number` literal in a record that is itself a field of a let-bound record is read through two field accesses and used as a `Float`.
  • elm / LetNumberDestructureTest
    Two `number` literals bound by a tuple pattern in a `let` are both used as `Float`s.
  • elm / LetNumberDualUseTest
    An unannotated let-bound `number` value can be used as an `Int` and as a `Float` in the same expression, because Elm generalizes the type of a `let` binding and each use picks its own type.
  • elm / LetNumberFloatArithCrashTest
    An unannotated let-bound `number` literal passed to `sqrt`, or combined with a `Float` by `(+)`, `(/)` or `(^)`, is a `Float`.
  • elm / LetNumberFoldrTest
    A let-bound list of `number` literals is folded by `List.foldr` with a `Float` accumulator, which makes its elements `Float`s.
  • elm / LetNumberIfBranchTest
    A let-bound `number` passed through an `if` expression whose result is multiplied by a `Float` is a `Float`.
  • elm / LetNumberIndirectCaptureTest
    A let-bound `number` captured by an anonymous function and multiplied by that function's `Float` argument is a `Float`.
  • elm / LetNumberIndirectFoldlTest
    A let-bound `number` used as the initial accumulator of `List.foldl (+)` over a list of `Float`s is a `Float`.
  • elm / LetNumberIndirectIdentityTest
    A let-bound `number` passed through `identity` before a `Float` multiplication is a `Float`.
  • elm / LetNumberIndirectTopFnTest
    A let-bound `number` passed to a top-level function annotated `Float -> Float` is a `Float`.
  • elm / LetNumberLetInLambdaTest
    A `number` bound in a `let` inside a top-level function's body and multiplied by a `Float` is a `Float`.
  • elm / LetNumberListConsHeadTest
    The head of a list of `number` literals, matched by a `::` pattern in a `case` and multiplied by a `Float`, is a `Float`.
  • elm / LetNumberListFixedTest
    Both elements of a list of `number` literals, matched by the fixed-length list pattern `[ a, b ]` and multiplied by a `Float`, are `Float`s.
  • elm / LetNumberListOfClosuresTest
    A let-bound `number` captured by two anonymous functions stored in a list, each applied to a `Float`, is a `Float`.
  • elm / LetNumberListOfMaybeTest
    `number` literals inside `Just` values in a let-bound list, mapped with a `Float` multiplication, are `Float`s.
  • elm / LetNumberListOfRecordsTest
    `number` fields of records in a let-bound list, mapped with a `Float` multiplication, are `Float`s.
  • elm / LetNumberLocalMap2Test
    A list of integer literals combined with a list of `Float`s by a two-argument mapping function is used at `Float`: `[ 30, 40 ]` scaled by 1.5 and rounded logs `[45,60]`.
  • elm / LetNumberLogBaseTest
    An unannotated let-bound integer literal, passed to `logBase`, is used as a `Float`: `round (logBase 10 n)` with `n = 100` logs 2.
  • elm / LetNumberMaybeCaseDirectTest
    An integer literal inside `Just`, taken out by a `case` pattern and multiplied by `1.5`, is used as a `Float`: `round (n * 1.5)` with `n` bound from `Just 30` logs 45.
  • elm / LetNumberMaybeChainTest
    An integer literal inside `Just`, run through two `Maybe.map` calls, is used as a `Float`: `Just 30` multiplied by `1.5`, divided by 3 and rounded logs 15.
  • elm / LetNumberMixedTupleSlotTest
    Two integer literals in a three-element tuple whose middle element is a `String` are each used as a `Float`: matching `( 30, "x", 40 )` against `( a, _, c )` and adding `round (a * 1.5)` to `round (c * 1.5)` logs 105.
  • elm / LetNumberMulFnTest
    An unannotated let-bound integer literal passed to a user function annotated `Float -> Float -> Float` is used as a `Float`: `round (mulF 1.5 n)` with `n = 30` logs 45.
  • elm / LetNumberNegateTest
    An unannotated let-bound integer literal passed through `negate` twice and then to `sqrt` is used as a `Float`: `round (sqrt (negate (negate n)))` with `n = 144` logs 12.
  • elm / LetNumberNestedLetTest
    An integer literal bound in one `let` and re-bound in a nested `let` is used as a `Float`: `n = 30`, then `m = n`, then `round (m * 1.5)` logs 45.
  • elm / LetNumberNestedTupleTest
    Integer literals in the inner tuple of a nested tuple are used as `Float`s while the outer one stays an `Int`: matching `( ( 30, 40 ), 50 )` against `( ( a, b ), c )` and computing `round (a * 1.5) + round (b * 1.5) + c` logs 155.
  • elm / LetNumberRecordDestructureTest
    Integer-literal record fields bound by a let destructuring pattern are used as `Float`s: `{ lo, hi } = { lo = 30, hi = 40 }` followed by `round (lo * 1.5) + round (hi * 1.5)` logs 105.
  • elm / LetNumberRecordMultiFieldTest
    Two integer-literal fields of one let-bound record, read as `r.lo` and `r.hi`, are each used as a `Float`: `round (r.lo * 1.5) + round (r.hi * 1.5)` with `r = { lo = 30, hi = 40 }` logs 105.
  • elm / LetNumberRecordToFnTest
    An unannotated let-bound integer literal, placed in a record passed to a function that takes `{ v : Float }`, is used as a `Float`: `round (useFloat { v = base })` with `base = 30` logs 45.
  • elm / LetNumberResultMapTest
    An integer literal inside `Ok`, mapped by `Result.map`, is used as a `Float`: `Result.map (\x -> round (x * 1.5)) (Ok 30)`, unwrapped by a `case`, logs 45.
  • elm / LetNumberScaleFnTest
    A let-bound record of integer literals passed to a function that takes a record of `Float`s is used at `Float`: `round (scale 1.5 p)` with `p = { lo = 30, hi = 40 }` logs 105.
  • elm / LetNumberSumMapTest
    A let-bound list of integer literals, mapped to `Float`s and summed, is used at `Float`: `round (List.sum (List.map (\x -> x * 1.5) [ 30, 40 ]))` logs 105.
  • elm / LetNumberTupleBothTest
    Both integer-literal elements of a let-bound pair are used as `Float`s: `round (Tuple.first p * 1.5) + round (Tuple.second p * 1.5)` with `p = ( 30, 40 )` logs 105.
  • elm / LetNumberTupleRecordNestTest
    An integer-literal record field and an integer-literal tuple element, from a record nested in a pair, are both used as `Float`s: matching `( { lo = 30 }, 40 )` against `( r, c )` and computing `round (r.lo * 1.5) + round (c * 1.5)` logs 105.
  • elm / LetNumberTupleSecondTest
    The second integer-literal element of a let-bound pair, read with `Tuple.second`, is used as a `Float` while the first is never used: `round (Tuple.second p * 1.5)` with `p = ( 99, 30 )` logs 45.
  • elm / LetNumberTupleToFnTest
    A let-bound pair of integer literals passed to a function that takes `( Float, Float )` is used at `Float`: `round (useTuple p)` with `p = ( 30, 40 )` logs 105.
  • elm / LetNumberWildcardSlotTest
    The first and last integer literals of a three-element tuple are used as `Float`s while the middle one is matched by a wildcard: matching `( 30, 40, 50 )` against `( a, _, c )` and adding `round (a * 1.5)` to `round (c * 1.5)` logs 120.
  • elm / NumberGenericAppCustom
    A number literal passed through a generic function, here `unbox : Box a -> a` applied to `Box 30`, keeps the type `number`, so the `let`-bound result can be used in `Float` arithmetic: `round (1.5 * n)` logs 45.
  • elm / NumberGenericAppList
    A number literal passed through a generic function, here `List.head` followed by `Maybe.withDefault 0`, keeps the type `number`, so the `let`-bound result can be used in `Float` arithmetic: `round (1.5 * n)` logs 45.
  • elm / NumberGenericAppMaybe
    A number literal passed through a generic function, here `Maybe.withDefault 0` applied to `Just 30`, keeps the type `number`, so the `let`-bound result can be used in `Float` arithmetic: `round (1.5 * n)` logs 45.
  • elm / NumberGenericAppTuple
    A number literal passed through a generic function, here `Tuple.first` applied to `( 30, "x" )`, keeps the type `number`, so the `let`-bound result can be used in `Float` arithmetic: `round (1.5 * n)` logs 45.
  • elm / StandardA99RecordPatternAsTest
    A record pattern under `as` in a `let` binding.
  • elm / StandardA99RecordPatternBothTest
    A variable bound by a record pattern in a `let`, used at Int and at Float.
  • elm / StandardA99RecordPatternDependentTest
    A `let` definition that uses a variable bound by a record pattern.
  • elm / StandardA99RecordPatternFloatTest
    A variable bound by a record pattern in a `let`, used at Float.
  • elm / StandardA99RecordPatternFunctionTest
    A function bound by a record pattern in a `let`, applied at Int and at Float.
  • elm / StandardA99RecordPatternInTopCopyTest
    A record pattern in a `let` inside a top-level value that is itself copied.
  • elm / StandardA99RecordPatternInTupleTest
    A record pattern inside the tuple pattern of a `let` binding.
  • elm / StandardA99RecordPatternIntTest
    A variable bound by a record pattern in a `let`, used at Int.
  • elm / StandardA99RecordPatternLambdaTest
    A record pattern in a lambda inside a `let` binding that is copied.
  • elm / StandardA99RecordPatternSharedVariableTest
    Two variables of one record pattern that share one `number` type.
  • elm / StandardA99RecordPatternTwoVariablesTest
    Two variables of one record pattern, with independent `number` types, used at opposite types.
  • elm / TooManyArgsTooManyArgumentsToALiteralTest
    An integer literal applied to an argument is rejected with a TOO MANY ARGS error.
  • elm / TypeMismatchBoolPatternTest
    A `True` pattern in a `case` on a number is rejected with a TYPE MISMATCH.
  • elm / TypeMismatchCharUnderIntTest
    A value annotated `Int` but defined as the character `'c'` is rejected with a TYPE MISMATCH.
  • elm / TypeMismatchConstructorPatternTest
    A `case` on the number `1` with a `Just a` branch is rejected with a TYPE MISMATCH, because the pattern is a `Maybe` and the value is a number.
  • elm / TypeMismatchFloatLeftOfIntDivideTest
    The compiler rejects the `Float` literal `1.5` on the left of the integer division operator `//`, with a TYPE MISMATCH error.
  • elm / TypeMismatchFloatRightOfIntDivideTest
    The compiler rejects the `Float` literal `1.5` on the right of the integer division operator `//`, with a TYPE MISMATCH error.
  • elm / TypeMismatchFloatUnderIntTest
    The compiler rejects the `Float` literal `1.5` as the body of a definition annotated `Int`, with a TYPE MISMATCH error.
  • elm / TypeMismatchIfConditionIntTest
    The compiler rejects an `if` whose condition is the number `1` rather than a `Bool`, with a TYPE MISMATCH error.
  • elm / TypeMismatchListPatternTest
    Matching a number against a list pattern is rejected with a TYPE MISMATCH.
  • elm / TypeMismatchNumberLeftOfAndTest
    A number as the left operand of `&&` (`1 && True`) is rejected with a TYPE MISMATCH error, because `&&` takes two `Bool`s.
  • elm / TypeMismatchNumberLeftOfOrTest
    A number as the left operand of `||` (`1 || True`) is rejected with a TYPE MISMATCH error, because `||` takes two `Bool`s.
  • elm / TypeMismatchNumberListEntryWithAnAliasTest
    A list literal holding a number and a value of the record alias `N` (`[ 1, n ]`) is rejected with a TYPE MISMATCH error.
  • elm / TypeMismatchRigidComparableAsANumberTest
    Returning a number literal where the annotation promises a `comparable` is rejected with a TYPE MISMATCH.

Discussions

Discuss this rule·Search the discussions on GitHub

Discussions are on GitHub; one about this rule has [r:s-atexp-scon] 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.