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" : String
> "Hello Friend"
"Hello Friend" : String
> ['w', 'o', 'a', 'h']
['w', 'o', 'a', 'h'] : List Char
> ("hey", 42.42, ['n', 'o'])
("hey", 42.42, ['n', 'o']) : ( String, Float, List Char )
> (1, 2.1, 3, 4.3, 'c')
(1,2.1,3,4.3,'c') : ( number, Float, number', Float, Char )
> {}
{} : {}
> { hey = "Hi", someNumber = 43 }
{ hey = "Hi", someNumber = 43 } : { hey : String, someNumber : number }
> ()
() : ()
{}
is the empty Record type, and ()
is the empty Tuple type. The latter is often used for the purposes of lazy evaluation. See the corresponding example in Functions and Partial Application.
Note how number
appears uncapitalized. This indicates that it is a Type Variable, and moreover the particular word number
refers to a Special Type Variable that can either be an Int
or a Float
(see the corresponding sections for more). Types though are always upper-case, such as Char
, Float
, List String
, et cetera.