A categorical programming language
修订版 | 5ce1d98b359ee6713b42fc7ae9185980024ecf9b (tree) |
---|---|
时间 | 2022-03-30 09:21:26 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Implement the Yoneda combinators and other stuff.
@@ -0,0 +1,4 @@ | ||
1 | +(pair/mapfst (comp (pair (fun/name @0) id) fun/int-comp)) | |
2 | + | |
3 | +The dynamics of a deterministic automaton. The second component of the pair is | |
4 | +left free, but usually is a status value, like a Boolean. |
@@ -0,0 +1,3 @@ | ||
1 | +The type $\mathbb{N} + 1$ can be interpreted as $\mathbb{\tilde{N}}$, the | |
2 | +type of extended natural numbers, via [one-point | |
3 | +compactification](https://ncatlab.org/nlab/show/one-point+compactification). |
@@ -0,0 +1,6 @@ | ||
1 | +(comp | |
2 | + (sum/mapleft nat/pred-maybe) | |
3 | + (comp sum/assr (comp (sum/mapright sum/swap) sum/assl))) | |
4 | + | |
5 | +The predecessor of an extended natural number. The extra point signals when | |
6 | +the input is zero. |
@@ -0,0 +1,4 @@ | ||
1 | +(sum/mapleft succ) | |
2 | + | |
3 | +The successor of an extended natural number is also an extended natural | |
4 | +number. |
@@ -1,3 +1,3 @@ | ||
1 | -(curry (comp (comp fun/assr (pair fst (comp snd fun/app))) fun/app)) | |
1 | +(curry (comp (comp pair/assr (pair fst (comp snd fun/app))) fun/app)) | |
2 | 2 | |
3 | 3 | An internalized version of composition. |
@@ -0,0 +1,3 @@ | ||
1 | +(comp (pair ignore id) (uncurry @0)) | |
2 | + | |
3 | +Reference an arrow by name. |
@@ -1,4 +1,3 @@ | ||
1 | -(comp (fold | |
2 | - (pair @0 nil) | |
3 | - (comp (comp fun/assl (pair @1 snd)) (pair fst cons))) | |
4 | -snd) | |
1 | +(comp (fold (pair @0 nil) (comp (comp pair/assl (pair @1 snd)) (pair fst cons))) snd) | |
2 | + | |
3 | + |
@@ -1,7 +1,4 @@ | ||
1 | -(curry | |
2 | - (comp | |
3 | - (comp fun/assr (pair fst (comp snd fun/app))) | |
4 | - (comp fun/distribr (case fun/app (comp ignore right))))) | |
1 | +(curry (comp (comp pair/assr (pair fst (comp snd fun/app))) (comp fun/distribr (case fun/app (comp ignore right))))) | |
5 | 2 | |
6 | 3 | An internalized version of composition in the Kleisli category for the maybe |
7 | 4 | monad. |
@@ -0,0 +1,2 @@ | ||
1 | +The type $[\mathbb{N}]$ can be interpreted as the type of polynomials with | |
2 | +coefficients in $\mathbb{N}$. |
@@ -0,0 +1,3 @@ | ||
1 | +(comp (pair id (fun/const nil)) cons) | |
2 | + | |
3 | +A constant polynomial which always evaluating to the given natural number. |
@@ -0,0 +1,3 @@ | ||
1 | +(comp list/len nat/pred) | |
2 | + | |
3 | +The largest exponent in a polynomial. |
@@ -0,0 +1,3 @@ | ||
1 | +nil | |
2 | + | |
3 | +The zero polynomial. |
@@ -0,0 +1,3 @@ | ||
1 | +(case (comp left left) (case (comp right left) right)) | |
2 | + | |
3 | +Reassociate a triple sum to the left. |
@@ -0,0 +1,3 @@ | ||
1 | +(case (case left (comp left right)) (comp right right)) | |
2 | + | |
3 | +Reassociate a triple sum to the right. |
@@ -0,0 +1,2 @@ | ||
1 | +Given some fixed arrow $f : X \to Y$, its Yoneda embedding can be realized by | |
2 | +the type $\hat{f} : (X^Z) \to (Y^Z)$. |
@@ -0,0 +1,3 @@ | ||
1 | +(curry (comp fun/app @0)) | |
2 | + | |
3 | +The Yoneda embedding of an arrow. |
@@ -0,0 +1,3 @@ | ||
1 | +(fun/unname (comp (fun/const (fun/name id)) @0)) | |
2 | + | |
3 | +Undo the Yoneda embedding. |
@@ -3,7 +3,8 @@ | ||
3 | 3 | ["first component", "(pair X Y)", "X"], |
4 | 4 | ["right unitor", "X", "(pair X 1)"], |
5 | 5 | ["name of id", "1", "(hom X X)"], |
6 | - ["associator", "(pair (pair X Y) Z)", "(pair X (pair Y Z))"], | |
6 | + ["product associator", "(pair (pair X Y) Z)", "(pair X (pair Y Z))"], | |
7 | + ["sum associator", "(sum (sum X Y) Z)", "(sum X (sum Y Z))"], | |
7 | 8 | ["application", "(pair (hom X Y) X)", "Y"], |
8 | 9 | ["braiding", "(pair X Y)", "(pair Y X)"], |
9 | 10 | ["distributivity", "(sum (pair X Y) (pair X Z))", "(pair X (sum Y Z))"], |
@@ -60,3 +60,4 @@ | ||
60 | 60 | * We need to iter-maybe but also keep track of how many steps were taken |
61 | 61 | * Instead of X -> [N, Y + 1], we need X -> [N, N x (Y + 1)] |
62 | 62 | * ulimit jellification? |
63 | +* formal power series N -> Q |