Tutorial by Examples

Two-element tuples (,) is an example of a type that has a Bifunctor instance. instance Bifunctor (,) where bimap f g (x, y) = (f x, g y) bimap takes a pair of functions and applies them to the tuple's respective components. bimap (+ 2) (++ "nie") (3, "john") --> (5,...
If mapping covariantly over only the first argument, or only the second argument, is desired, then first or second ought to be used (in lieu of bimap). first :: Bifunctor f => (a -> c) -> f a b -> f c b first f = bimap f id second :: Bifunctor f => (b -> d) -> f a b -> f...
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 operation...

Page 1 of 1