First Steps With Elm

December 1, 2017 ยท 2 minute read

For my computer languages class I decided to evaluate Elm. Having not spend as much time on functional languages as I would have liked I figured this would be a good oportunity to expand my functional programming brain. These simple examples are the result of doing the exercises found in the Elm Documentation.


This first example is a basic form with validation. I augmented the form tutorial from the Elm Docs. My source can be found here.

The exercises in the tutorial were to augment the form in the following ways:

Random Dice

The random tutorial can be found here.

I augmented the example provided in the following ways:

Again the source is found on GitHub here.

The main trick here is to augment the model to contain a list of dice and then update it with a generator that generates a new list of dice based on the numDice in the model.

type alias Model =
  { dice  :  (List Int)
  , numDice  :  Int


update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case msg of
    Roll ->
      (model, Random.generate NewDice (dieGenerator model.numDice))

    NewDice dice ->
      ({ model | numDice  = dice }, Cmd.none)