Evaluation Order

  • From left to right.
  • Function arguments evals by value by default.
  • You can change this by insert => before type annotation in function defination. For example:
    // instead of
    fn and(a: Boolean, b: Boolean): Boolean =
    	if (a) b else false
    // use eval by name like this
    fn and(a: Boolean, b: => Boolean): Boolean = 
    	if (a) b else false

Function Type

// (Int, Int) => Int
def sum(a: Int, b: Int): Int = a + b
 

Curing

Expansion of Multiple Parameter List

In general, a definition of a function with multiple parameter lists

where n > 1, is equivalent to

where is a fresh identifier. Or for short:

More Function Types

The type of function bellow is(Int => Int) => (Int, Int) => Int. Note that function types are right associate. So the above type is equivalent to (Int => Int) => ((Int, Int) => Int)

def sum(f: Int => Int)(a: Int, b: Int): Int = ...