TL;DR
You will learn how to create your first Elm application. This post is part of the functional language series, and it is based on a remarkable book Programming Elm Build Safe and Maintainable Front-End Applications by Jeremy Fairbank.
Elm language’s main purpose is to help you in creating Browser applications. Magic is that Elm source compiles into optimized Javascript. The compilation is a rather complicated automated process of transforming file content from source to target. For example, Browser compiles Javascript into your processor machine code. The processor only understands machine code.
With elm init
, you initialize your elm project. In your working folder, you get src
folder where your elm source files go, and the `elm.json` file is created where elm stores your initial project configuration.
JSON stands for JavaScript object notation, and its first purpose was to put JavaScript object description in human-readable form. You can see a lot of {}
, []
, :
and "
that are used to organize items into logical sections. Here you can add your src directories or add more elm libraries that your application requires. JSON is now widely accepted, and it could be used in various programming languages (Elixir). In REST API communication, JSON format is used for data transfer.
This is our first elm application. The file must have the same name as the module, Main.elm
. We are exposing the main
function that is the entry point to our application. As our main
function is using text
function of Html module
, we need to expose text function.
elm make
creates our application in index.html
file. When we opened it in the Browser, we see "Hello, Elm!" index.html
is a big file. It contains JavaScript functions that are part of Elm.Browser
, Elm.Core
and Elm.Html
modules.
Remember
- how and when to initialize Elm project
- where to put Elm source files
- what is the purpose of
elm.json
file and what isjson.
- purpose of Elm
Main, Html
,Core
, andBrowser
modules - how to compile your application
- how to run your application