HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

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
classclass Bifunctor (p :: Type -> Type -> Type) where
#

The Bifunctor class

Laws

If bimap is supplied, then bimap id id = id

Methods

  • bimap :: (a %1 -> b) -> (c %1 -> d) -> p a c %1 -> p b d
  • first :: (a %1 -> b) -> p a c %1 -> p b c
  • second :: (b %1 -> c) -> p a b %1 -> p a c
Instances2Bifunctor
  • Bifunctor EitherDefined in linear-base-0.4.0 · Data.Bifunctor.Linear.Internal.Bifunctor
  • Bifunctor Tuple2Defined in linear-base-0.4.0 · Data.Bifunctor.Linear.Internal.Bifunctor
classclass Bifunctor m => SymmetricMonoidal (m :: Type -> Type -> Type) u | m -> u, u -> m where
#

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 the a

  • You can use the dual, i.e., rassoc :: ((a,b),c) %1-> (a,(b,c)) and then second

  • 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)
  • lassoc :: m a (m b c) %1 -> m (m a b) c
  • swap :: m a b %1 -> m b a
Instances2SymmetricMonoidal