Haskell Language Bifunctor Definition of Bifunctor


Example

Bifunctor is the class of types with two type parameters (f :: * -> * -> *), both of which can be covariantly mapped over simultaneously.

class Bifunctor f where
    bimap :: (a -> c) -> (b -> d) -> f a b -> f c d

bimap can be thought of as applying a pair of fmap operations to a datatype.

A correct instance of Bifunctor for a type f must satisfy the bifunctor laws, which are analogous to the functor laws:

bimap id id = id  -- identity
bimap (f . g) (h . i) = bimap f h . bimap g i  -- composition

The Bifunctor class is found in the Data.Bifunctor module. For GHC versions >7.10, this module is bundled with the compiler; for earlier versions you need to install the bifunctors package.