-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧩 [consolidate]: Category instance for GC.
- Loading branch information
Showing
5 changed files
with
56 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
module GaloisConnection where | ||
|
||
import Prelude | ||
import Data.Function (identity) as F | ||
|
||
import Data.Newtype (class Newtype) | ||
import Lattice (class BooleanLattice, neg) | ||
import Util (Endo) | ||
|
||
-- a and b are posets, but we don't enforce that here. Use record rather than type class so we can extend with | ||
-- explicit value-level representation of domain/codomain. | ||
type GaloisConnection a b = | ||
{ dom :: a | ||
, codom :: b | ||
, fwd :: a -> b | ||
, bwd :: b -> a | ||
} | ||
newtype GaloisConnection a b = GC { fwd :: a -> b, bwd :: b -> a } | ||
|
||
derive instance Newtype (GaloisConnection a b) _ | ||
|
||
deMorgan :: forall a b. BooleanLattice a => BooleanLattice b => Endo (a -> b) | ||
deMorgan = (neg >>> _) >>> (_ >>> neg) | ||
|
||
-- Could unify deMorgan and dual but would need to reify notion of opposite category. | ||
dual :: forall a b. BooleanLattice a => BooleanLattice b => GaloisConnection a b -> GaloisConnection b a | ||
dual gc = gc { dom = gc.codom, codom = gc.dom, fwd = deMorgan gc.bwd, bwd = deMorgan gc.fwd } | ||
dual (GC { fwd, bwd }) = GC { fwd: deMorgan bwd, bwd: deMorgan fwd } | ||
|
||
instance Semigroupoid GaloisConnection where | ||
compose (GC { fwd: fwd1, bwd: bwd1 }) (GC { fwd: fwd2, bwd: bwd2 }) = | ||
GC { fwd: fwd1 <<< fwd2, bwd: bwd1 >>> bwd2 } | ||
|
||
identity :: forall a. a -> GaloisConnection a a | ||
identity a = { dom: a, codom: a, fwd: F.identity, bwd: F.identity } | ||
instance Category GaloisConnection where | ||
identity = GC { fwd: identity, bwd: identity } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters