Wiki2
Haskell (changes)

Showing changes from revision #12 to #13: Added | Removed | Changed

Haskell

A* Shortest Path in Haskell

Order of parameters and currying

  • Type definitions with -> operator is right associative.
  • Function calls with parameters separated by space (” “) are left associative.
  • Parameters are ordered from left to right both in type definitions and function calls.

For example see the type definition of div.

> :t div
:: (Integral a) => a -> a -> a
  • Numbering the parameters, a1 -> a2 -> a3
  • Using right associative rule for -> operator, a1 -> (a2 -> a3)

So the type definition roughly translates to:

  1. A value of a1 applied to function div evaluates a function
  2. A value of type a2 applied to this function evaluates to a value of type a3

Calling divwith parameters 10 and 2 give the result 5.

> div 10 2
=> 5
  • Using left associative rule for parameters in function calls, (div 10) 2

This means that the function returned by applying 10 to div translates to 10/x. 2 applied to this function evaluates to 5. 10 is of type a1, 2 of type a2 and 5 of type a3.

The infix operator of div works in the same manner.

> :t (/)
:: (Fractional a) => a -> a -> a

> (/) 10 2
=> 5.0

> 10 / 2
=> 5.0

> 10 `div`  2
=> 5

References