Tutorial by Examples

Function application syntax in Elm does not use parenthesis or commas, and is instead whitespace-sensitive. To define a function, specify its name multiplyByTwo and arguments x, any operations after equal sign = is what returned from a function. multiplyByTwo x = x * 2 To call a function, ...
Elm has a special syntax for lambda expressions or anonymous functions: \arguments -> returnedValue For example, as seen in List.filter: > List.filter (\num -> num > 1) [1,2,3] [2,3] : List number More to the depth, a backward slash, \, is used to mark the beginning of lambda ex...
It is possible to define local variables inside a function to reduce code repetition give name to subexpressions reduce the amount of passed arguments. The construct for this is let ... in .... bigNumbers = let allNumbers = [1..100] isBig number = ...
Partial application means calling a function with less arguments than it has and saving the result as another function (that waits for the rest of the arguments). multiplyBy: Int -> Int -> Int multiplyBy x y = x * y multiplyByTwo : Int -> Int -- one Int has disappeared! we ...
In elm, a function's value is computed when the last argument is applied. In the example below, the diagnostic from log will be printed when f is invoked with 3 arguments or a curried form of f is applied with the last argument. import String import Debug exposing (log) f a b c = String.join &...
Elm allows the definition of custom infix operators. Infix operators are defined using parenthesis around the name of a function. Consider this example of infix operator for construction Tuples 1 => True -- (1, True): (=>) : a -> b -> ( a, b ) (=>) a b = ( a, b ) Most of t...

Page 1 of 1