Rule 173p-stat-main-program
Comments
Rules (173) and (174) cover the one production, since main may have either of two forms of type. Only the main of the main module is constrained; a main in another module is an ordinary value. The scheme of main is taken from , the environment of all the declarations of the module, not from its interface, so main need not be exposed. A bound variable of class in the scheme of main is in its type: with init = \() -> (0, Cmd.none) and no other constraint on the model, the model type is , and the value of main is that of its default copy, at (rule (176)). The flags type is a port type, and is taken from the scheme before the default, so it contains no type variable. Thus main : Program (Int -> Int) Model Msg and main : Program flags Model Msg, with flags a type variable, do not elaborate, and nor does an unannotated main whose init is \n -> (n + 1, Cmd.none), whose flags type is a variable of class . The unit type is a port type, and as flags it is treated specially (Section 9.4). Since Bytes is a port type, flags may be, or contain, values of type Bytes. The model type and the message type are unconstrained. Some implementations admit further types of flags, which are not port types (Appendix E).
Referred to from
TeX source
\defnrule[r:p-stat-main-program]
{\jdg{\pgBstat}{\modm}{\pgBstat',E}\\
\Dom(\PE\of\pgBstat')\cap\big(\Dom(\PE\of\pgBstat)\cup\effMgrPlat\big)=\emptyset\\
E(\kw{main})=(\sigma,\isv)\premsep
\sigma=\forall\tyrowvar^{(k)}.(\tau_1,\tau_2,\tau_3)\sbtProgram\premsep
\Port(\tau_1)}
{\jstat{\pgBstat}{\modm}{\big(\pgDflt\sigma,\ \PE\of(\pgBstat+\pgBstat')\big)}}Tests (12)
- elm / BadMainRecursiveMainTestAn annotated `main` that is mutually recursive with another function is rejected with a BAD MAIN error.
- elm / BadMainRecursiveUnannotatedMainTestAn unannotated `main` that is mutually recursive with another function is rejected with a BAD MAIN error.
- elm / BadMainTypeAliasMainTestA `main` whose type is a record type alias is rejected with a BAD MAIN TYPE error.
- elm / BadMainTypeFunctionMainTestA `main` of function type `Int -> Int -> Int` is rejected with a BAD MAIN TYPE error.
- elm / BadMainTypeRecordMainTestA `main` of record type `{ a : Int, b : ( Int, Int, Int ) }` is rejected with a BAD MAIN TYPE error.
- elm / BadMainTypeThreeArgumentTypeMainTestA `main` whose type is a custom type with three type parameters is rejected with a BAD MAIN TYPE error.
- elm / BadMainTypeTypeVariableMainTestAn unannotated `main` whose inferred type contains a type variable is rejected with a BAD MAIN TYPE error.
- elm / BadMainTypeUnitMainTestA `main` of type `()` is rejected with a BAD MAIN TYPE error.
- elm / FlagsRecordTestA `Platform.worker` whose flags are a record of an `Int`, a `String` and a `Bool` receives the decoded record in `init`.
- elm / StandardA82MainInImportedModuleTestA `main` in a module other than the main module is an ordinary value, of any type.
- elm / StandardA84DuplicatePortNameTestTwo ports of one program may not have the same name.
- elm / StandardA96NumberFlagsTestA `main` whose flags type is a `number` variable is refused.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:p-stat-main-program] 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.