linear-base-0.1.0: Standard library for linear types.
Safe HaskellSafe-Inferred
LanguageHaskell2010

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 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
Synopsis

Documentation

class Bifunctor p where Source #

The Bifunctor class

Laws

If bimap is supplied, then bimap id id = id

Minimal complete definition

bimap | first, second

Methods

bimap :: (a %1 -> b) -> (c %1 -> d) -> (a `p` c) %1 -> b `p` d Source #

first :: (a %1 -> b) -> (a `p` c) %1 -> b `p` c Source #

second :: (b %1 -> c) -> (a `p` b) %1 -> a `p` c Source #

Instances

Instances details
Bifunctor Either Source # 
Instance details

Defined in Data.Bifunctor.Linear.Internal.Bifunctor

Methods

bimap :: (a %1 -> b) -> (c %1 -> d) -> Either a c %1 -> Either b d Source #

first :: (a %1 -> b) -> Either a c %1 -> Either b c Source #

second :: (b %1 -> c) -> Either a b %1 -> Either a c Source #

Bifunctor (,) Source # 
Instance details

Defined in Data.Bifunctor.Linear.Internal.Bifunctor

Methods

bimap :: (a %1 -> b) -> (c %1 -> d) -> (a, c) %1 -> (b, d) Source #

first :: (a %1 -> b) -> (a, c) %1 -> (b, c) Source #

second :: (b %1 -> c) -> (a, b) %1 -> (a, c) 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 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

Minimal complete definition

swap, (rassoc | lassoc)

Methods

rassoc :: ((a `m` b) `m` c) %1 -> a `m` (b `m` c) Source #

lassoc :: (a `m` (b `m` c)) %1 -> (a `m` b) `m` c Source #

swap :: (a `m` b) %1 -> b `m` a Source #

Instances

Instances details
SymmetricMonoidal Either Void Source # 
Instance details

Defined in Data.Bifunctor.Linear.Internal.SymmetricMonoidal

Methods

rassoc :: Either (Either a b) c %1 -> Either a (Either b c) Source #

lassoc :: Either a (Either b c) %1 -> Either (Either a b) c Source #

swap :: Either a b %1 -> Either b a Source #

SymmetricMonoidal (,) () Source # 
Instance details

Defined in Data.Bifunctor.Linear.Internal.SymmetricMonoidal

Methods

rassoc :: ((a, b), c) %1 -> (a, (b, c)) Source #

lassoc :: (a, (b, c)) %1 -> ((a, b), c) Source #

swap :: (a, b) %1 -> (b, a) Source #