Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Bifunctor.Linear
Description
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 :: Type -> Type -> Type) where Source #
The Bifunctor class
Laws
Methods
bimap :: (a %1 -> b) -> (c %1 -> d) -> p a c %1 -> p b d Source #
class Bifunctor m => SymmetricMonoidal (m :: Type -> Type -> Type) u | 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
Methods
rassoc :: m (m a b) c %1 -> m a (m b c) Source #