Skip to content

elm-guides/elm-for-js

Repository files navigation

elm-for-js

Community driven Elm guide for JS people

This guide will augment the official Elm docs as needed, for a smooth transitions for people coming from JavaScript.

Getting started

  1. Try the Hello World online
  2. Install Elm via npm or the installer.
  3. Get Hello World running locally
  4. Work through the architecture examples. Type manually, look in examples/ for help.

Getting Hello World running locally

  1. Install Elm
  2. Create a new file Main.elm in a new folder.
  3. $ elm package install to set up elm-package.json and elm-stuff/ for deps (similar to node).
  4. Paste the source from the Hello World example to your local Main.elm file.
  5. $ elm package install evancz/elm-html to install the missing package dependency.
  6. $ elm-reactor to get the dev server running at http://0.0.0.0:8000/.
  7. Success!
  8. For a standalone file you can run $ elm make Main.elm --output=main.html (default is a JS file).

Type Annotations

Writing them is optional, but highly encouraged. Type annotations improve code by helping you think about what the function should be doing, and serve as compiler-verified documentation. In addition, if you ever want to publish a third-party library, you need type annotations.

-- A variable of type Int.
answer : Int
answer = 42

-- An update function that takes 2 params - an Action, then a Model and returns a Model (last).
update : Action -> Model -> Model

In JavaScript, params are handled at the same time. In Elm, they are curried. For example:

-- Update is a function that will take an Action param, and return a function that will take a Model param. THAT fn will return a Model.
update : Action -> Model -> Model

Great elm articles

If you see mistakes, or something you want covered, open an issue or a PR.

TODO:

Add sections for

  • Package management (compare to node_modules, npm)
  • Type Annotations
  • Data types (try not to duplicate official docs)
  • Basic Syntax
  • Program structure and flow
  • How to read the API docs
  • Package catalog link.

About

Community driven Elm guide for JS people

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published