Skip to content
Brian Marick edited this page Apr 27, 2017 · 2 revisions

Problem 1

1+2*3 is 7. It would be 9 if it were evaluated left to right. So Elm has operator precedence, the same as most languages. The precedence is irrelevant when you're using an operator as a function:

> (+) 1 ( (*) 2 3 )
7 : number

Problem 2

The first example shows how an empty list is printed.

> List.take 0 [1, 2, 3]
[] : List number

The second and third show that Elm's tolerant of taking more elements than are in a list, or even of a nonsensical integer argument.

> List.take 4 [1, 2, 3]
[1,2,3] : List number
> List.take -1 [1, 2, 3]
[] : List number

The last example shows that Elm is not tolerant of the wrong type of argument. You can't use a Float when List.take is defined to take an Int.

> List.take 1.3 [1, 2, 3]
-- TYPE MISMATCH --------------------------------------------- repl-temp-000.elm
3|   List.take 1.3 [1, 2, 3]
               ^^^
Function `take` is expecting the 1st argument to be:

    Int

But it is:

    Float

You can't tell when working in the repl, but the error happened when the line was compiled. The function List.take was never actually called (or applied). If you were compiling a whole program (using elm-make), such an error wouldn't produce any compiled code for you to run.

Clone this wiki locally