The Bifunctor class
Modulelinear-base-0.4.0Haskell2010
Data.Bifunctor.Linear
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 as or bs.
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- 2 classes
- Packagelinear-base-0.4.0
- Exports2
- LanguageHaskell2010
- LicenceMIT
- SourceLinear.hs
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 use first to access theaYou can use the dual, i.e.,
rassoc :: ((a,b),c) %1-> (a,(b,c))and then secondYou can swap the first and second values with
swap :: (a,b) %1-> (b,a)
Laws
swap . swap = idrassoc . lassoc = idlassoc . rassoc = idsecond swap . rassoc . first swap = rassoc . swap . rassoc
Instances2SymmetricMonoidal
SymmetricMonoidal Either VoidDefined in linear-base-0.4.0 · Data.Bifunctor.Linear.Internal.SymmetricMonoidalSymmetricMonoidal Tuple2 ()Defined in linear-base-0.4.0 · Data.Bifunctor.Linear.Internal.SymmetricMonoidal