Haskell/Functions

From Wikiversity
Jump to navigation Jump to search

Functions in Haskell are one of its fundamental constructs. Some familiar functions like addition or multiplication are binary, taking two arguments and returning a single value. Formally, functions are binary relations between two sets, such that each member of the first set maps exactly to one member of the second set. 1 + 1 will always return 2, at least in decimal.

In Haskell, functions are largely defined not only by their definitions,

f x = x

but also by their declarations, which contain the types of their inputs and outputs.

f :: Integer -> Integer

bounds x to the set of Integers, which maps directly to the set of Integers. (1 == 1, after all)

Functions can be thought of abstractly as black boxes, which take input and return output. This is the basis for the lambda calculus, another heavy influencer of Haskell.