Elm Exactly

Rule 56sm-topdec-value

Top-level DeclarationsC⊢topdec⇒E,PE\jdg{C}{\topdec}{E, \PE}
C+VE⊢valbind⇒VEVE′=ClosCVEC⊢valbind⇒VE′ in Env, {}\frac{\begin{array}{c}\jdg{C + \VE}{\valbind}{\VE} \premsep \VE' = \Clos_C \VE\end{array}}{\begin{array}{c}\jdg{C}{\valbind}{\VE'\ \text{in}\ \Env,\ \emptymap}\end{array}}
(56)
Read it in its chapter·Permanent address: /standard/rules/sm-topdec-value

Comments

The rule is that for declarations in the Core (rule (19)): a group of top-level values is recursive, an unannotated member is monomorphic within its group, and the closure makes every top-level value polymorphic in its other uses. At the top level the restriction on recursive values is syntactic and weaker than in a let (Section 3.7), so f = \n -> f n elaborates here.

Referred to from

TeX source
\defnrule[r:sm-topdec-value]
  {\jdg{C + \VE}{\valbind}{\VE} \premsep \VE' = \Clos_C \VE}
  {\jdg{C}{\valbind}{\VE'\ \text{in}\ \Env,\ \emptymap}}

Tests (40)

  • elm / AliasForwardTest
    Top-level values defined as another function, `dup = twice` and `plus = (+)`, behave like the function they name.
  • elm / CombinatorBComposeTest
    The B combinator, function composition, built only from S and K: `b square inc 4` is `square (inc 4)`, which is 25.
  • elm / CombinatorBSumMapTest
    The B combinator, built from S and K, composing `sum` with a partially applied `map`: the sum of `[ 1, 2, 3 ]` each plus one is 9.
  • elm / CombinatorCConsTest
    The C combinator, which swaps two arguments, built from S and K and applied to the cons operator: `c (::) [ 2, 3 ] 1` is `1 :: [ 2, 3 ]`.
  • elm / CombinatorCFlipTest
    The C combinator, which swaps two arguments, built from S and K: `c sub 10 3` is `sub 3 10`, which is -7.
  • elm / CombinatorIIdentityTest
    The I combinator, identity, written as `s k k`: `i 42` is 42.
  • elm / CombinatorListStringTest
    SKI-style combinators applied to lists, strings and functions over them, each printing its result.
  • elm / CombinatorRefIdentityBugTest
    A B combinator defined with all its arguments, `b f g y = s (k s) k f g y`, used in the same program as a separate application of `s` to a different function: `b square inc 4` must still be `square (inc 4)`, which is 25.
  • elm / CombinatorTPipeTest
    The T combinator, built from S and K, passing `[ 1, 2, 3 ]` to the composition of `sum` and `map ((*) 2)`: the result is 12.
  • elm / CombinatorTThrushTest
    The T combinator, which applies its second argument to its first, built from S and K: `t 7 (\x -> x * 3)` is 21.
  • elm / CombinatorTest
    SKI-style combinators, most of them built from S and K, each applied to `Int` arguments and printing its result.
  • elm / CompilerIssue1858AnnotatedPolymorphicRecursionTest
    A recursive call at a different type argument is rejected despite the annotation.
  • elm / CompilerIssue1890RecordUpdateMutualRecursionCrashTest
    Mutually recursive unannotated functions with a record update crash the compiler.
  • elm / CompilerIssue1964AnnotatedPolymorphicRecursionWrapperTest
    A recursive call at a wrapped type argument is rejected despite the annotation.
  • elm / CompilerIssue2057CallSiteChangesInferredTypeTest
    Two annotated callers of a function with unannotated mutually recursive let functions are wrongly rejected.
  • elm / CompilerIssue2119MutualRecursionUnannotatedTest
    An exposed, unannotated, mutually recursive function used from another module compiles and runs.
  • elm / CompilerIssue2207MutualRecursionSecondFunctionTest
    The second of two exposed, unannotated, mutually recursive functions can be used from another module.
  • elm / CompilerIssue2274MutualRecursionTransmuteTest
    The compiler rejects `eraseType : a -> b` because the unannotated mutually recursive `f` and `g` only have type `a -> b -> b`.
  • elm / CovLambdaBoundaryCaseBoundaryInARecursiveValueTest
    A top-level function defined as a lambda whose `case` returns a different lambda per branch, one of which calls the function recursively.
  • elm / CovTailRecPairParameterPassedUnchangedLetBoundAndRebuiltTest
    Self tail-recursive functions with a pair parameter that is destructured in a `let`, then passed on unchanged, rebuilt with its components swapped, or replaced by a `let`-bound pair.
  • elm / CovTailRecPairParametersSwappedAndALoopReturningALambdaTest
    Self tail-recursive functions over pair parameters: one that swaps a pair's components or exchanges its two pair arguments, and one that returns a lambda in its base case.
  • elm / CovTailRecSplitATripleParameterTest
    A self tail-recursive function that destructures a triple of `Int`, `Int` and `Float` in its parameter pattern and rebuilds it on each call.
  • 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 / FunctionUnannotatedCompappendTest
    A module containing an unannotated function that both compares and appends its arguments compiles, with the type `compappend` inferred.
  • elm / LssGapNoDecls
    A program with no type declarations calls one annotated top-level function.
  • elm / MutualRecursionTest
    Two top-level functions that call each other, `isEven` and `isOdd`, decide parity by counting down to zero.
  • elm / MutualRecursionThreeWayTest
    Three top-level functions that call each other in a cycle (`funcA` calls `funcB`, `funcB` calls `funcC`, `funcC` calls `funcA`) recurse correctly.
  • elm / NonZeroArityRecursionTest
    A self-recursive top-level function, `countDown : Int -> Int`, calls itself in tail position from 100 down to 0 and returns 0; the program logs `countDown: 0`.
  • elm / PolyApplyLambdaTest
    Tests a polymorphic `apply f x = f x` called with an `Int` function, a `String` function and an anonymous lambda.
  • elm / PolySpecializeRecursiveTest
    Annotated polymorphic recursive functions, `myLength` and `myMap`, give the right results when called at both `Int` and `String` element types.
  • elm / PolyTailRecReverseTest
    An unannotated, polymorphic, tail-recursive list reverse gives the right result at both `Int` and `String` element types.
  • elm / PureMutualRecursiveValueTest
    Two top-level values that refer to each other through lambdas can be defined and used.
  • elm / PureRecursiveValueThunkTest
    A top-level value that refers to itself inside a lambda can be defined and used.
  • elm / RecordAccessorFunctionCaseTest
    A record accessor function `.x` stored in a top-level value can be applied to a record.
  • elm / RecursiveFactorialTest
    A self-recursive top-level `factorial` returns 1 for 0 and 120 and 3628800 for 5 and 10.
  • elm / RecursiveFibonacciTest
    A top-level `fib` that calls itself twice per step returns 0, 1 and 55 for 0, 1 and 10.
  • elm / RecursiveListLengthTest
    A self-recursive function that pattern matches on `[]` and `_ :: rest` counts the elements of lists of length 0, 3 and 5.
  • elm / RecursiveTopLevelLambdaTest
    A top-level value defined as a lambda that refers to itself can be called recursively.
  • elm / RecursiveTreeTest
    A recursive binary tree type can be summed and measured with recursive functions.
  • elm / TailRecursiveSumTest
    A tail-recursive accumulator function sums the integers from 1 to n correctly for n = 5, 10 and 100.

Discussions

Discuss this rule·Search the discussions on GitHub

Discussions are on GitHub; one about this rule has [r:sm-topdec-value] 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.