invertible-0.1.2: 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

Instances

Category * a => Category * (Bijection a) Source # 

Methods

id :: cat a a #

(.) :: cat b c -> cat a b -> cat a c #

Semigroupoid * a => Groupoid * (Bijection a) Source # 

Methods

inv :: k1 a b -> k1 b a #

Semigroupoid * a => Semigroupoid * (Bijection a) Source # 

Methods

o :: c j k1 -> c i j -> c i k1 #

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.

Methods

arr :: (b -> c) -> Bijection a b c #

first :: Bijection a b c -> Bijection a (b, d) (c, d) #

second :: Bijection a b c -> Bijection a (d, b) (d, c) #

(***) :: Bijection a b c -> Bijection a b' c' -> Bijection a (b, b') (c, c') #

(&&&) :: Bijection a b c -> Bijection a b c' -> Bijection a b (c, c') #

ArrowChoice a => ArrowChoice (Bijection a) Source #

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

Methods

left :: Bijection a b c -> Bijection a (Either b d) (Either c d) #

right :: Bijection a b c -> Bijection a (Either d b) (Either d c) #

(+++) :: Bijection a b c -> Bijection a b' c' -> Bijection a (Either b b') (Either c c') #

(|||) :: Bijection a b d -> Bijection a c d -> Bijection a (Either b c) d #

ArrowZero a => ArrowZero (Bijection a) Source # 

Methods

zeroArrow :: Bijection a b c #

Invariant2 (Bijection (->)) Source # 

Methods

invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> Bijection (->) a b -> Bijection (->) c d #

(Semigroupoid * a, Arrow a) => BiArrow' (Bijection a) Source # 
(Semigroupoid * a, Arrow a) => BiArrow (Bijection a) Source # 

Methods

(<->) :: (b -> c) -> (c -> b) -> Bijection a b c Source #

invert :: Bijection a b c -> Bijection a c b Source #

Monad m => Arrow (MonadArrow (<->) m) # 

Methods

arr :: (b -> c) -> MonadArrow (<->) m b c #

first :: MonadArrow (<->) m b c -> MonadArrow (<->) m (b, d) (c, d) #

second :: MonadArrow (<->) m b c -> MonadArrow (<->) m (d, b) (d, c) #

(***) :: MonadArrow (<->) m b c -> MonadArrow (<->) m b' c' -> MonadArrow (<->) m (b, b') (c, c') #

(&&&) :: MonadArrow (<->) m b c -> MonadArrow (<->) m b c' -> MonadArrow (<->) m b (c, c') #

Monad m => ArrowChoice (MonadArrow (<->) m) # 

Methods

left :: MonadArrow (<->) m b c -> MonadArrow (<->) m (Either b d) (Either c d) #

right :: MonadArrow (<->) m b c -> MonadArrow (<->) m (Either d b) (Either d c) #

(+++) :: MonadArrow (<->) m b c -> MonadArrow (<->) m b' c' -> MonadArrow (<->) m (Either b b') (Either c c') #

(|||) :: MonadArrow (<->) m b d -> MonadArrow (<->) m c d -> MonadArrow (<->) m (Either b c) d #

MonadPlus m => ArrowZero (MonadArrow (<->) m) # 

Methods

zeroArrow :: MonadArrow (<->) m b c #

MonadPlus m => ArrowPlus (MonadArrow (<->) m) # 

Methods

(<+>) :: MonadArrow (<->) m b c -> MonadArrow (<->) m b c -> MonadArrow (<->) m b c #

Invariant (Bijection (->) b) Source # 

Methods

invmap :: (a -> b) -> (b -> a) -> Bijection (->) b a -> Bijection (->) b b #

Monad m => BiArrow' (MonadArrow (<->) m) Source # 
(Semigroupoid * a, Arrow a) => Functor (Bijection a b) Source # 

Methods

fmap :: (a <-> b) -> Bijection a b a -> Bijection a b b Source #

Monoidal (Bijection (->) ()) Source # 

Methods

unit :: Bijection (->) () () Source #

(>*<) :: Bijection (->) () a -> Bijection (->) () b -> Bijection (->) () (a, b) 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.