-
Notifications
You must be signed in to change notification settings - Fork 8
Applying functions
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 : numberProblem 2
The first example shows how an empty list is printed.
> List.take 0 [1, 2, 3]
[] : List numberThe 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 numberThe 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.