base-4.2.0.0: Basic librariesSource codeContentsIndex
Data.Function
Portabilityportable
Stabilityexperimental
Maintainerlibraries@haskell.org
Contents
Prelude re-exports
Other combinators
Description
Simple combinators working solely on and with functions.
Synopsis
id :: a -> a
const :: a -> b -> a
(.) :: (b -> c) -> (a -> b) -> a -> c
flip :: (a -> b -> c) -> b -> a -> c
($) :: (a -> b) -> a -> b
fix :: (a -> a) -> a
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
Prelude re-exports
id :: a -> aSource
Identity function.
const :: a -> b -> aSource
Constant function.
(.) :: (b -> c) -> (a -> b) -> a -> cSource
Function composition.
flip :: (a -> b -> c) -> b -> a -> cSource
flip f takes its (first) two arguments in the reverse order of f.
($) :: (a -> b) -> a -> bSource

Application operator. This operator is redundant, since ordinary application (f x) means the same as (f $ x). However, $ has low, right-associative binding precedence, so it sometimes allows parentheses to be omitted; for example:

     f $ g $ h x  =  f (g (h x))

It is also useful in higher-order situations, such as map ($ 0) xs, or Data.List.zipWith ($) fs xs.

Other combinators
fix :: (a -> a) -> aSource
fix f is the least fixed point of the function f, i.e. the least defined x such that f x = x.
on :: (b -> b -> c) -> (a -> b) -> a -> a -> cSource

(*) `on` f = \x y -> f x * f y.

Typical usage: Data.List.sortBy (compare `on` fst).

Algebraic properties:

  • (*) `on` id = (*) (if (*) ∉ {⊥, const ⊥})
  • ((*) `on` f) `on` g = (*) `on` (f . g)
  • flip on f . flip on g = flip on (g . f)
Produced by Haddock version 2.6.0