Functions

When we define a new function, we can give it a type signature. For example double is a function takes an Integer and gives an Integer doubled as output.

  1. double :: Integer -> Integer
  2. double x = x * 2

Lambda Expression

There are also lambda expressions in Hamler, here is an example of how we rewrite double.

  1. double' :: Integer -> Integer
  2. double' = \x -> 2 * x

It becomes really handy when we need to make an anonymous function.

Currying

  1. --Curry
  2. --This is uncurried (+)
  3. add :: (Integer, Integer) -> Integer
  4. add (x, y) = x + y
  5. --This is curried (+)
  6. plus :: Integer -> Integer -> Integer
  7. plus x y = x + y

Partial Application

  1. -- plus :: Integer -> (Integer -> Integer) This is one of the example of higher order functions
  2. >:t plus 2
  3. plus 2:: Integer -> Integer
  4. >let plusTwo = plus2
  5. >plusTwo 3
  6. 5