Options

Question 2.8 - Bifunctors

Bifunctors.

A bifunctor is a polymorphic type constructor F that takes two variables together with an implementation of a function:

bimap :: (a -> b) -> (c -> d) -> F a c -> F b d

Using the universal property of the coproduct, provide an implementation of bimap for the sum type constructor Either a b.


Next Prev All

Comments

  • 1.

    bimap :: (a -> b) -> (c -> d) -> Either a c -> Either b d

    bimap f g (Left x) = Left (f x)

    bimap f g (Right y) = Right (g y)

    Comment Source:> bimap :: (a -> b) -> (c -> d) -> Either a c -> Either b d > bimap f g (Left x) = Left (f x) > bimap f g (Right y) = Right (g y)
Sign In or Register to comment.