Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- data Kan
- data Conn (k :: Kan) a b
- embed :: Conn k a b -> b -> a
- type Trip a b = forall k. Conn k a b
- pattern Conn :: (a -> b) -> (b -> a) -> (a -> b) -> Conn k a b
- trip :: (a -> b) -> (b -> a) -> (a -> b) -> Trip a b
- range :: Trip a b -> a -> (b, b)
- type ConnL = Conn L
- pattern ConnL :: (a -> b) -> (b -> a) -> ConnL a b
- swapL :: ConnR a b -> ConnL b a
- downL :: ConnL a b -> ConnL (Down b) (Down a)
- unitL :: ConnL a b -> a -> a
- counitL :: ConnL a b -> b -> b
- lowerL :: ConnL a b -> a -> b
- lowerL1 :: ConnL a b -> (a -> a) -> b -> b
- lowerL2 :: ConnL a b -> (a -> a -> a) -> b -> b -> b
- upperL1 :: ConnL a b -> (b -> b) -> a -> a
- upperL2 :: ConnL a b -> (b -> b -> b) -> a -> a -> a
- type ConnR = Conn R
- pattern ConnR :: (b -> a) -> (a -> b) -> ConnR a b
- swapR :: ConnL a b -> ConnR b a
- downR :: ConnR a b -> ConnR (Down b) (Down a)
- unitR :: ConnR a b -> b -> b
- counitR :: ConnR a b -> a -> a
- upperR :: ConnR a b -> a -> b
- upperR1 :: ConnR a b -> (a -> a) -> b -> b
- upperR2 :: ConnR a b -> (a -> a -> a) -> b -> b -> b
- lowerR1 :: ConnR a b -> (b -> b) -> a -> a
- lowerR2 :: ConnR a b -> (b -> b -> b) -> a -> a -> a
- choice :: Conn k a b -> Conn k c d -> Conn k (Either a c) (Either b d)
- strong :: Conn k a b -> Conn k c d -> Conn k (a, c) (b, d)
- fmapped :: Functor f => Conn k a b -> Conn k (f a) (f b)
Conn
A data kind distinguishing the chirality of a Kan extension.
Here it serves to distinguish the directionality of a preorder:
- L-tagged types are 'upwards-directed'
- R-tagged types are 'downwards-directed'
data Conn (k :: Kan) a b Source #
An adjoint string of Galois connections of length 2 or 3.
embed :: Conn k a b -> b -> a Source #
Obtain the center of a Trip, upper half of a ConnL, or the lower half of a ConnR.
Trip
type Trip a b = forall k. Conn k a b Source #
An adjoint triple of Galois connections.
An adjoint triple is a chain of connections of length 3:
\(f \dashv g \dashv h \)
For detailed properties see Property
.
trip :: (a -> b) -> (b -> a) -> (a -> b) -> Trip a b Source #
Obtain a forall k. Conn k from an adjoint triple of monotone functions.
Caution: Conn f g h
must obey \(f \dashv g \dashv h\). This condition is not checked.
range :: Trip a b -> a -> (b, b) Source #
Obtain the lower and upper functions from a Trip
.
range c = upperR c &&& lowerL c
>>>
range f64f32 pi
(3.1415925,3.1415927)>>>
range f64f32 (0/0)
(NaN,NaN)
ConnL
A Galois connection between two monotone functions.
A Galois connection between f and g, written \(f \dashv g \) is an adjunction in the category of preorders.
Each side of the connection may be defined in terms of the other:
\( g(x) = \sup \{y \in E \mid f(y) \leq x \} \)
\( f(x) = \inf \{y \in E \mid g(y) \geq x \} \)
For further information see Property
.
Caution: Monotonicity is not checked.
pattern ConnL :: (a -> b) -> (b -> a) -> ConnL a b Source #
A view pattern for a ConnL
.
Caution: ConnL f g must obey \(f \dashv g \). This condition is not checked.
unitL :: ConnL a b -> a -> a Source #
Round trip through a connection.
unitL c = upperL1 c id = embed c . lowerL c x <= unitL c x
>>>
compare pi $ unitL f64f32 pi
LT
counitL :: ConnL a b -> b -> b Source #
Reverse round trip through a connection.
x >= counitL c x
>>>
counitL (conn @_ @() @Ordering) LT
LT>>>
counitL (conn @_ @() @Ordering) GT
LT
ConnR
A Galois connection between two monotone functions.
ConnR
is the mirror image of ConnL
:
swapR :: ConnL a b -> ConnR b a
If you only require one connection there is no particular reason to use one version over the other.
However some use cases (e.g. rounding) require an adjoint triple
of connections (i.e. a Trip
) that can lower into a standard
connection in either of two ways.
pattern ConnR :: (b -> a) -> (a -> b) -> ConnR a b Source #
A view pattern for a ConnR
.
Caution: ConnR f g must obey \(f \dashv g \). This condition is not checked.
unitR :: ConnR a b -> b -> b Source #
Round trip through a connection.
unitR c = upperR1 c id = upperR c . embed c x <= unitR c x
>>>
unitR (conn @_ @() @Ordering) LT
GT>>>
unitR (conn @_ @() @Ordering) GT
GT
counitR :: ConnR a b -> a -> a Source #
Reverse round trip through a connection.
x >= counitR c x
>>>
compare pi $ counitR f64f32 pi
GT
upperR :: ConnR a b -> a -> b Source #
Extract the upper half of a connection.
When a and b are lattices we have:
upperR c (x1 /\ x2) = upperR c x1 /\ upperR c x2
This is the adjoint functor theorem for preorders.
>>>
upperR f64f32 pi
3.1415925>>>
lowerL f64f32 pi
3.1415927
Connections
choice :: Conn k a b -> Conn k c d -> Conn k (Either a c) (Either b d) Source #
Lift two Conn
s into a Conn
on the coproduct order
(choice id) (ab >>> cd) = (choice id) ab >>> (choice id) cd (flip choice id) (ab >>> cd) = (flip choice id) ab >>> (flip choice id) cd