Piso-0.1: Partial isomorphisms

Safe HaskellSafe-Inferred




Partial isomorphisms

data Piso a b Source

Bidirectional isomorphism that is partial in the backward direction.

This can be used to express constructor-deconstructor pairs. For example:

 nil :: Piso t ([a] :- t)
 nil = Piso f g
     f        t  = [] :- t
     g ([] :- t) = Just t
     g _         = Nothing

 cons :: Piso (a :- [a] :- t) ([a] :- t)
 cons = Piso f g
     f (x :- xs  :- t) = (x : xs) :- t
     g ((x : xs) :- t) = Just (x :- xs :- t)
     g _               = Nothing

Here :- can be read as 'cons', forming a stack of values. For example, nil pushes [] onto the stack; or, in the backward direction, tries to remove [] from the stack. Representing constructor-destructor pairs as stack manipulators allows them to be composed more easily.

Module Data.Piso.Common contains Pisos for some common datatypes.

Modules Data.Piso.Generic and Data.Piso.TH offer generic ways of deriving Pisos for custom datatypes.


Piso (a -> b) (b -> Maybe a) 

forward :: Piso a b -> a -> bSource

Apply an isomorphism in forward direction.

backward :: Piso a b -> b -> Maybe aSource

Apply an isomorphism in backward direction.

class Category cat => FromPiso cat whereSource

A type class that expresses that a category is able to embed Piso values.


fromPiso :: Piso a b -> cat a bSource


data h :- t Source

Heterogenous stack with a head and a tail. Or: an infix way to write (,).


h :- t 


Functor (:- h) 
(Eq h, Eq t) => Eq (:- h t) 
(Show h, Show t) => Show (:- h t)