Tutorial by Examples

Comparable types are primitive types that can be compared using comparison operators from Basics module, like: (<), (>), (<=), (>=), max, min, compare Comparable types in Elm are Int, Float, Time, Char, String, and tuples or lists of comparable types. In documentation or type definitio...
In Elm, values are declared by writing a name, an equals sign, and then the actual value: someValue = 42 Functions are also values, with the addition of taking a value or values as arguments. They are usually written as follows: double n = n * 2 Every value in Elm has a type. The types of th...
In elm-repl, type a piece of code to get its value and inferred type. Try the following to learn about the various types that exist: > 42 42 : number > 1.987 1.987 : Float > 42 / 2 21 : Float > 42 % 2 0 : Int > 'e' 'e' : Char > "e" "e" : St...
Type variables are uncapitalized names in type-signatures. Unlike their capitalized counterparts, such as Int and String, they do not represent a single type, but rather, any type. They are used to write generic functions that can operate on any type or types, and are particularly useful for writing...
Sometimes we want to give a type a more descriptive name. Let's say our app has a data type representing users: { name : String, age : Int, email : String } And our functions on users have type signatures along the lines of: prettyPrintUser : { name : String, age : Int, email : String } -> S...
Aliasing types cuts down on boilerplate and enhances readability, but it is no more type-safe than the aliased type itself is. Consider the following: type alias Email = String type alias Name = String someEmail = "[email protected]" someName = "Benedict" sendEmail ...
The type alias keyword combination gives a new name for a type, but the type keyword in isolation declares a new type. Let's examine one of the most fundamental of these types: Maybe type Maybe a = Just a | Nothing The first thing to note is that the Maybe type is declared with a type ...
The Never type cannot be constructed (the Basics module hasn't exported its value constructor and hasn't given you any other function that returns Never either). There is no value never : Never or a function createNever : ?? -> Never. This has its benefits: you can encode in a type system a poss...
Elm defines the following special type variables that have a particular meaning to the compiler: comparable: Comprised of Int, Float, Char, String and tuples thereof. This allows the use of the < and > operators. Example: You could define a function to find the smallest and largest eleme...

Page 1 of 1