A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Hello World in Elm page! Here, you'll find the source code for this program as well as a description of how the program works.
module HelloWorld exposing (..)
import Html exposing (text)
main =
text "Hello, World!"
Hello World in Elm was written by:
This article was written by:
If you see anything you'd like to change or update, please consider contributing.
As usual, let's dive right into the implementation of Hello World in Elm.
We can write Hello World in Elm in just a few lines of code, but what's really going on in this code?
Up first, we have the module declaration line. In other
words, we've defined a module with the name HelloWorld
.
If anyone wanted to use this module, everything would be
completely exposed.
In the third line, we import the Html
module, so we can
access the text functionality. As we can probably imagine,
the text
function just displays text to the user.
Finally, as with many functional languages, we have the
main
function. To no surprise, the main
function is a
special function which provides the starting point for
the program. In the case of Elm, the main
function must
retain an element to draw into the page. In our case, we're
returning a HTML element from the text function.
Okay, so we have a solution, but how do we run it? Well, Elm is a bit different than our typical languages because it's for web use only. As a result, we'll want to download the necessary utilities first.
Now would be a good time to install Elm. With that installed, get the Html package from the command line:
elm-package install elm-lang/html
After that, grab a copy of the elm solution from GitHub. Now, in the same folder as the new file, run the following from the command line:
elm reactor
This will basically launch a local server for testing. Now, go to the local server location in a browser and open the HelloWorld file. That's it!
Alternatively, use an online Elm compiler for testing code snippets. Give it a go!