/compiler

Compiler for Elm, a functional language for reliable webapps.

Primary LanguageHaskellBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

The Elm Compiler + JS Modules

Build Status

  • This feature branch reintroduces JS modules for any elm application or package

Install

git clone ..
stack build

# The binary is then in:
echo $(stack path --local-install-root)/bin/elm[.exe]

Example

  • elm init
  • Create a Javascript module, src/Elm/Kernel/JS.js
  • Important notes:
    • Javascript modules must be in a Elm/Kernel/ folder
// Nothing crazy here, the JS.log function logs the string and returns it
function _JS_log(s) {
    console.log(s);
    return s;
}
  • Create an Elm module to call our javascript, src/Main.elm
module Main exposing(..)

import Html exposing (..)
import Elm.Kernel.JS

log : String -> String
log = Elm.Kernel.JS.log

main = text <| log <| "HelloWorld"
  • Compile elm make src/Main.elm
  • Open index.html
    • "HelloWorld" should be printed to the console and on the page
  • More js module examples are here elm/core library.