Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides Bifunctor and related classes.
Bifunctor
Use a bifunctor instance to map functions over data structures
that have two type paramaters a
and b
and could be have a
functor instance for either the a
s or b
s.
For instance, you might want to map a function on either the left
or right element of a (Int, Bool)
:
import Prelude.Linear import Data.Bifunctor.Linear -- Map over the second element negateRight :: (Int, Bool) %1-> (Int, Bool) negateRight x = second not x
Documentation
class Bifunctor p where Source #
The Bifunctor class
Laws
bimap :: (a %1 -> b) -> (c %1 -> d) -> (a `p` c) %1 -> b `p` d Source #
class Bifunctor m => SymmetricMonoidal (m :: Type -> Type -> Type) (u :: Type) | m -> u, u -> m where Source #
A SymmetricMonoidal class
This allows you to shuffle around a bifunctor nested in itself and swap the places of the two types held in the bifunctor. For instance, for tuples:
- You can use
lassoc :: (a,(b,c)) %1-> ((a,b),c)
and then usefirst
to access thea
- You can use the dual, i.e.,
rassoc :: ((a,b),c) %1-> (a,(b,c))
and thensecond
- You can swap the first and second values with
swap :: (a,b) %1-> (b,a)
Laws
swap . swap = id
rassoc . lassoc = id
lassoc . rassoc = id
second swap . rassoc . first swap = rassoc . swap . rassoc
rassoc :: ((a `m` b) `m` c) %1 -> a `m` (b `m` c) Source #