A categorical programming language
リビジョン | 21782876c22e894e34939d075ca8e01ba655d28b (tree) |
---|---|
日時 | 2022-03-17 14:10:00 |
作者 | Corbin <cds@corb...> |
コミッター | Corbin |
Write out some basic docs for the hive.
@@ -1,4 +1,4 @@ | ||
1 | 1 | let |
2 | 2 | makeBuilder = import ./builder.nix; |
3 | 3 | in |
4 | - makeBuilder ./draw.py "cammy-draw" false # true | |
4 | + makeBuilder ./draw.py "cammy-draw" true |
@@ -48,6 +48,14 @@ def main(argv): | ||
48 | 48 | section = dirpath[prefix:] or "Top level" |
49 | 49 | doc.append("# " + section) |
50 | 50 | |
51 | + # Optionally include section-specific information if present. | |
52 | + aboutpath = os.path.join(dirpath, "about.md") | |
53 | + try: | |
54 | + with open(aboutpath, "r") as handle: | |
55 | + doc.append(handle.read()) | |
56 | + except IOError: | |
57 | + doc.append("(Undocumented section)") | |
58 | + | |
51 | 59 | for filename in filenames: |
52 | 60 | if not filename.endswith(".cammy"): |
53 | 61 | continue |
@@ -0,0 +1,3 @@ | ||
1 | +This hive provides some basic tools for approximating and visualizing | |
2 | +functions on real numbers. It includes a demonstration renderer for iterated | |
3 | +fractal systems. |
@@ -0,0 +1,2 @@ | ||
1 | +The exponential type $\mathbb{N}^\mathbb{N}$ can be interpreted as [Baire | |
2 | +space](https://en.wikipedia.org/wiki/Baire_space_(set_theory)). |
@@ -0,0 +1 @@ | ||
1 | +The Boolean type $2$ contains exactly two elements. |
@@ -0,0 +1 @@ | ||
1 | +The product comonad is a comonad. |
@@ -0,0 +1 @@ | ||
1 | +The [store comonad](https://ncatlab.org/nlab/show/store+comonad) is a comonad. |
@@ -0,0 +1 @@ | ||
1 | +These Cammy expressions are included for demonstration purposes. |
@@ -0,0 +1 @@ | ||
1 | +The double type $X + X$ is isomorphic to the Boolen tag type $X \times 2$. |
@@ -0,0 +1,3 @@ | ||
1 | +The numeric type $F$ is a type of double-precision [IEEE | |
2 | +754](https://en.wikipedia.org/wiki/IEEE_754) floating-point numbers. Only | |
3 | +numbers are included; no elements of $F$ are not numbers. |
@@ -0,0 +1,2 @@ | ||
1 | +The function types ${Y}^{X}$ are the primary building blocks of Cammy | |
2 | +expressions. |
@@ -0,0 +1,6 @@ | ||
1 | +The type $N + N$ can be interpreted as the type of integers. Specifically, the | |
2 | +left-hand components are positive integers, the right-hand components are | |
3 | +negative integers, and zero can be represented as either left-hand zero or | |
4 | +right-hand zero. Under the equivalence with the type $N \times 2$, the | |
5 | +representation can be viewed as a natural number with a [sign | |
6 | +bit](https://en.wikipedia.org/wiki/Sign_bit). |
@@ -0,0 +1 @@ | ||
1 | +The list type $[X]$ is the free monoid over $X$. |
@@ -0,0 +1,11 @@ | ||
1 | +(comp | |
2 | + (pair/mapfst list/reverse) | |
3 | + (uncurry (fold | |
4 | + (fun/name (fun/const zero)) | |
5 | + (curry (comp | |
6 | + (pair (pair (comp fst fst) (fun/apppair (comp fst snd) snd)) snd) | |
7 | + (pair/of nat/add | |
8 | + (pair/of nat/mul (comp fst snd) snd) | |
9 | + (comp fst fst))))))) | |
10 | + | |
11 | +Evaluate a polynomial at an input coordinate using Horner's rule. |
@@ -0,0 +1,2 @@ | ||
1 | +The type $(X \times X) \times (X \times X)$ can be interpreted as a two-by-two | |
2 | +matrix over $X$. |
@@ -1,7 +1,3 @@ | ||
1 | -(comp | |
2 | - (fun/tensor id mat2/trans) | |
3 | - (pair | |
4 | - (mat2/vecpair fst (comp snd fst)) | |
5 | - (mat2/vecpair fst (comp snd snd)))) | |
1 | +(comp (fun/tensor id mat2/trans) (pair (mat2/vecpair fst (comp snd fst)) (mat2/vecpair fst (comp snd snd)))) | |
6 | 2 | |
7 | 3 | Multiply two matrices. |
@@ -0,0 +1,9 @@ | ||
1 | +A [continuation monad](https://ncatlab.org/nlab/show/continuation+monad) is a | |
2 | +codensity monad. The typical continuation monad arises from the | |
3 | +double-negation endofunctor | |
4 | + | |
5 | +$$ | |
6 | +D : X \mapsto {R}^{{R}^{X}} | |
7 | +$$ | |
8 | + | |
9 | +for some continuation type $R$. |
@@ -0,0 +1 @@ | ||
1 | +The either monad is a monad. |
@@ -0,0 +1,6 @@ | ||
1 | +The [maybe monad](https://ncatlab.org/nlab/show/maybe+monad) is the monad | |
2 | +carried by the endofunctor | |
3 | + | |
4 | +$$ | |
5 | +M : X \mapsto X + 1 | |
6 | +$$ |
@@ -0,0 +1 @@ | ||
1 | +The [reader monad](https://ncatlab.org/nlab/show/function+monad) is a monad. |
@@ -0,0 +1 @@ | ||
1 | +The [state monad](https://ncatlab.org/nlab/show/state+monad) is a monad. |
@@ -0,0 +1 @@ | ||
1 | +The elements of the type $\mathbb{N}$ are natural numbers. |
@@ -0,0 +1,2 @@ | ||
1 | +The type $X \times [X]$ can be interpreted as a type of nonempty lists of | |
2 | +$X$. The first component is the head of the list. |
@@ -0,0 +1,3 @@ | ||
1 | +cons | |
2 | + | |
3 | +A nonempty list is a list. |
@@ -0,0 +1,15 @@ | ||
1 | +The pair type $X \times Y$ is ubiquitous when programming with | |
2 | +Cartesian closed categories. Common uses for pairs include: | |
3 | + | |
4 | +* Passing multiple arguments to arrows | |
5 | +* Pairing a state with a projection or observation | |
6 | +* Placing a value to the side while performing an intermediate transformation | |
7 | +* Performing multiple transformations in parallel | |
8 | + | |
9 | +Pairs naturally form a comonad, the product comonad, carried by the endofunctor | |
10 | + | |
11 | +$$ | |
12 | +P : X \mapsto X \times A | |
13 | +$$ | |
14 | + | |
15 | +for some fixed type of observations $A$. |
@@ -0,0 +1,4 @@ | ||
1 | +The [Scott | |
2 | +encoding](https://en.wikipedia.org/wiki/Mogensen%E2%80%93Scott_encoding) of | |
3 | +an algebraic data type represents it as a set of arguments in a first-order | |
4 | +type signature. |
@@ -0,0 +1,2 @@ | ||
1 | +The Scott encoding for Booleans is the same as the [Church encoding for | |
2 | +Booleans](https://en.wikipedia.org/wiki/Church_encoding#Church_Booleans). |
@@ -1,5 +0,0 @@ | ||
1 | -(curry (curry (curry | |
2 | - (comp (pair | |
3 | - (comp (pair snd (comp (comp fst fst) fst)) fun/app) | |
4 | - (comp fst snd)) | |
5 | - fun/app)))) |
@@ -1 +0,0 @@ | ||
1 | -(curry fst) |
@@ -1,2 +0,0 @@ | ||
1 | -(comp (pair (comp (pair (fun/const (fun/name scott/nat/zero)) id) fun/app) | |
2 | - (fun/name id)) fun/app) |
@@ -1 +0,0 @@ | ||
1 | -(curry (curry (comp (pair snd (comp fst fst)) fun/app))) |
@@ -1,3 +0,0 @@ | ||
1 | -(curry fst) | |
2 | - | |
3 | -The Scott-encoded version of zero. |
@@ -0,0 +1,5 @@ | ||
1 | +The arrow type $F \times F \to F$ can be interpreted as a type of functions | |
2 | +from points in the 2-dimensional Cartesian plane to distances. In particular, | |
3 | +it may be interpreted as a type of [signed distance | |
4 | +functions](https://en.wikipedia.org/wiki/Signed_distance_function) in the | |
5 | +Cartesian plane. |
@@ -0,0 +1,8 @@ | ||
1 | +The square type $X ^ 2$ is isomorphic to the diagonal pair type $X \times X$. | |
2 | +The endofunctor | |
3 | + | |
4 | +$$ | |
5 | +Sq : X \mapsto X^2 | |
6 | +$$ | |
7 | + | |
8 | +is a special case of the endofunctor which carries the reader monad. |
@@ -0,0 +1,2 @@ | ||
1 | +The exponential type $2 ^ X$ can be interpreted as the type of subobjects of | |
2 | +$X$. However, $2$ is not a subobject classifier. |
@@ -0,0 +1 @@ | ||
1 | +The type $X + Y$ is a heterogenous sum type. |
@@ -0,0 +1,2 @@ | ||
1 | +The product type $X \times X$ can be interpreted as a 2-dimensional vector | |
2 | +space over $X$. |
@@ -0,0 +1,2 @@ | ||
1 | +The type $X \times ( X \times X )$ can be interpreted as a 3-dimensional | |
2 | +vector space over $X$. |
@@ -8,6 +8,8 @@ | ||
8 | 8 | * list/zip : [X] × [Y] → [X × Y] |
9 | 9 | * list/tail : [X] → [X] |
10 | 10 | * rat |
11 | + * Using binary quote notation? | |
12 | + * Continued fractions? | |
11 | 13 | * refactoring from the bikeshed: ignore -> ! |
12 | 14 | * Might not be important since fun/const is the only user! |
13 | 15 | * zero -> 0, f-zero -> f-0, f-one -> f-1 maybe? |
@@ -30,10 +32,7 @@ | ||
30 | 32 | * Subtypes? |
31 | 33 | * Interval type? |
32 | 34 | * Cantor's type of bitstrings: N -> 2 |
33 | -* The square type: For a type X, 2 -> X | |
34 | - * Another special case of reader monad | |
35 | - * There's an equivalence X x X <-> [2, X] | |
36 | - * Done? | |
35 | + * We have subobjects now, X -> 2 | |
37 | 36 | * Moore machines: For state type Q and input type S, Q × S -> Q |
38 | 37 | * Moore transducers: [Q × S, Q] -> [Q × S, Q] |
39 | 38 | * Mealy machines: For state type Q, input type S, and output type L, Q × S -> Q × L |
@@ -56,3 +55,4 @@ | ||
56 | 55 | * We now can iter-maybe, short-circuiting evaluation |
57 | 56 | * We need to iter-maybe but also keep track of how many steps were taken |
58 | 57 | * Instead of X -> [N, Y + 1], we need X -> [N, N x (Y + 1)] |
58 | +* ulimit jellification? |