stoft / baby-steps-elm

Getting Started with Elm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Baby Steps Elm

Knowledge repository, guide and exercises for people beginning with Elm.

Exercises are found under: Exercises

Notes

Functions

Currying

All functions in Elm are curried into one argument functions. E.g. a 3 argument function foo: (foo x y z)

Is converted to: (((foo x) y) z)

A function foo that takes one argument x, and returns a function that in turn takes an argument y, which in turn returns a function that takes an argument z.

References:

Associativity

As noted in the Elm Syntax functions are left associative. This means functions take left precedence which in turn means functions take precedence over operators since operators are infix functions.

Example:

> f n = n * 2
<function> : number -> number
> f 3 + 3
9 : number
> f (3 + 3)
12 : number

Broken down, what's happening is:

f 3 + 3 becomes (((+) (f 3)) 3) whereas f (3 + 3) becomes (f((+)(3) 3))

Function Type Declarations

Unlike functions, their type declarations are right associative.

A type declaration such as: foo : Int -> Int -> Int

Will have the following precedence: (Int -> (Int -> Int))

If you want a different precedence you have to explicitly declare this in your declaration. See e.g. List.map

About

Getting Started with Elm

License:Apache License 2.0


Languages

Language:Elm 100.0%