Haskell Language Bifunctor Definition of Bifunctor

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any Haskell Language Question?