invertible-0.1: bidirectional arrows, bijective functions, and invariant functors

Safe HaskellTrustworthy
LanguageHaskell2010

Data.Invertible.Bijection

Description

The base representation for bidirectional arrows (bijections).

Synopsis

Documentation

data Bijection a b c Source

A representation of a bidirectional arrow (embedding-projection pair of arrows transformer): an arrow and its inverse. Most uses will prefer the specialized <-> type for function arrows.

To constitute a valid bijection, biTo and biFrom should be inverses:

  • biTo . biFrom = id
  • biFrom . biTo = id

It may be argued that the arguments should be in the opposite order due to the arrow syntax, but it makes more sense to me to have the forward function come first.

Constructors

(:<->:) infix 2 

Fields

biTo :: a b c
 
biFrom :: a c b
 

Instances

Category * a => Category * (Bijection a) Source 
Semigroupoid * a => Groupoid * (Bijection a) Source 
Semigroupoid * a => Semigroupoid * (Bijection a) Source 
Arrow a => Arrow (Bijection a) Source

In order to use all the Arrow functions, we make a partially broken instance, where arr creates a bijection with a broken biFrom. See note on BiArrow'. &&& is first-biased, and uses only the left argument's biFrom.

ArrowChoice a => ArrowChoice (Bijection a) Source

||| is Left-biased, and uses only the left argument's biFrom.

ArrowZero a => ArrowZero (Bijection a) Source 
Invariant2 (Bijection (->)) Source 
(Semigroupoid * a, Arrow a) => BiArrow' (Bijection a) Source 
(Semigroupoid * a, Arrow a) => BiArrow (Bijection a) Source 
Monad m => Arrow (MonadArrow (<->) m) 
Monad m => ArrowChoice (MonadArrow (<->) m) 
MonadPlus m => ArrowZero (MonadArrow (<->) m) 
MonadPlus m => ArrowPlus (MonadArrow (<->) m) 
Invariant (Bijection (->) b) Source 
Monad m => BiArrow' (MonadArrow (<->) m) Source 
(Semigroupoid * a, Arrow a) => Functor (Bijection a b) Source 
Monoidal (Bijection (->) ()) Source 

type (<->) = Bijection (->) infix 2 Source

Specialization of Bijection to function arrows. Represents both a function, f, and its (presumed) inverse, g, represented as f :<->: g.