title | layout |
---|---|
Elm FAQ |
page |
This document is obsolete. It has been moved to elm-community.github.io/elm-faq and is being maintained there.
Here are some common questions that I've seen on the Elm IRC channel and on the mailing lists. Contributions to this document are welcome.
You need to install the Html module:
elm package install evancz/elm-html
Several modules are available by default in the base Elm tools but other common modules like Html have to be installed in the working directory before they can be used in elm-make, elm-repl, and elm-reactor.
elm-repl does not support type annotations at all. If you try you'll see a "syntax problem" message saying something like "I ran into something unexpected when parsing your code!" and pointing to the colon.
To use type annotations you will have to use elm-reactor or elm-lang.org/try, or build and run a complete app.
Search on package.elm-lang.org for the module name and use the package name that you find there.
Wrap any value with Debug.log “some message”
and that message and the value will be written to the javascript console every time the value is evaluated. For example:
case Debug.log "action" action of
If you want to just log a message and value without using that value, try this in a let
clause:
_ = Debug.log "my message" someValue
Effects.task (Task.succeed SomeAction)
npm install -g [email protected]
If you need to switch between multiple versions of elm, consider elmenv.
A common idiom is to define the (=>)
operator as a synonym for the (,)
operator that constructs tuples. This makes a shorthand for long lists of tuple pairs, often used with the Html.style property. So ["color" => "red", "padding" => "2px"]
means [("color", "red"), ("padding", "2px")]
.
Use the innerHTML
property. For example:
span [ property "innerHTML" (Json.Encode.string "©") ] []
It is the empty tuple or unit type. It serves much like "void", "null", or "None" in other languages.
It has lower precedence than function application expressed by adjacency (e.g. sqrt x
) and so it can be used instead of parentheses to group function arguments. For example, a b (c d)
is the same as a b <| c d
. More concretely, max 3 (sqrt x)
can be written as max 3 <| sqrt x
.
See an Elm operator precedence table. See also Basics.elm.
You need to set app.port
.
port tasks : Signal (Task.Task Never ())
port tasks =
app.tasks
It was removed in Elm version 0.16. You might use andMap
from
Signal.Extra
instead.
You can compile multiple modules into a single elm.js and then instantiate whatever module you need on the appropriate div. [ref]
elm-make A.elm B.elm --output elm.js
Sign up at elmlang.herokuapp.com.