• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A categorical programming language


Commit MetaInfo

修订版7f8b03a3d558edae73e0bc5bf258e9a097bb54e2 (tree)
时间2021-08-10 14:34:36
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Parse lists of nats.

Generalized lists of lists will need something recursive.

更改概述

差异

--- a/README.txt
+++ b/README.txt
@@ -1,4 +1,4 @@
1-To update Cargo dependencies:
1+To update Cargo dependencies for jelly:
22
33 * $ cargo metadata
44 * $ crate2nix generate
--- a/cammy.txt
+++ b/cammy.txt
@@ -56,3 +56,23 @@ Combinators with (*) are provided by OCaml by default; the others are in a
5656 stub module. Type-checking is achieved by copying the combinators into
5757 an OCaml expression; compilation is achieved by copying the combinators into
5858 a CHICKEN Scheme expression.
59+
60+In terms of the "principal programming paradigms"
61+https://www.info.ucl.ac.be/~pvr/paradigmsDIAGRAMeng101.pdf, Cammy is a
62+"functional programming" language; it possesses the ability to encode
63+arbitrary functions via topos theory. Later improvements may shift Cammy to
64+the "monotonic dataflow programming", "multi-agent dataflow programming", or
65+"event-loop programming" paradigms.
66+
67+In terms of the common taxonomy of type systems, exhibited for tutorial at
68+https://www.cs.uaf.edu/users/chappell/public_html/class/2018_spr/cs331/docs/types_primer.html,
69+Cammy's current toolchain implements a static, implicit, structural, sound
70+type system. For a classic example, the program (comp dup apply), sometimes
71+called the "Turing bird", will be rejected by the toolchain as ill-typed.
72+
73+In terms of the taxonomy of desugaring systems
74+https://cs.brown.edu/research/pubs/theses/phd/2018/pombrio.justin.pdf, Cammy
75+does not implement desugaring. Any nullary sugar can be implemented as plain
76+Cammy programs. Every algebraic equality in Cammy's combinators corresponds to
77+a desugaring rule in the toolchain, but those equalities are not taxonomically
78+syntactic sugar.
--- a/finish.py
+++ b/finish.py
@@ -9,6 +9,12 @@ parsers = {
99 "nat * nat": "string->int",
1010 }
1111
12+def get_parser(ty):
13+ if ty.endswith(" list"):
14+ return "(string->listof {})".format(get_parser(ty[:-5]))
15+ else:
16+ return parsers[ty]
17+
1218 with open(sys.argv[-1], "r", encoding="utf-8") as handle:
1319 line = handle.readlines()[-2]
1420
@@ -25,11 +31,11 @@ with open(sys.argv[-2], "r", encoding="utf-8") as handle:
2531
2632 print("""
2733 (import (chicken process-context))
28-(define parsers (map eval '({})))
34+(define parsers (list {}))
2935 (define parsed-args (zip-app parsers (command-line-arguments)))
3036 (begin
3137 (display (fold-left program (lambda (x f) (f x)) parsed-args))
3238 (newline))
3339 """.format(
34- " ".join(parsers[ty] for ty in tys),
40+ " ".join(get_parser(ty) for ty in tys),
3541 ))
--- /dev/null
+++ b/hive/nat/sum.cammy
@@ -0,0 +1 @@
1+(fold zero (uncurry nat/add))
--- a/stub.scm
+++ b/stub.scm
@@ -1,4 +1,5 @@
11 (import (chicken condition))
2+(import (chicken string))
23
34 (define id (lambda (x) x))
45 (define (comp f g) (lambda (x) (g (f x))))
@@ -30,14 +31,23 @@
3031 (define (fold x f)
3132 (lambda (l) (if (null? l) (x '()) (f (cons (car l) ((fold x f) (cdr l)))))))
3233
34+(define (parse-error message) (signal (condition (list 'exn 'message message))))
3335 (define (string->unit s) '())
3436 (define (string->boolean s) (equal? s "true"))
3537 (define (string->nat s)
3638 (let ((i (string->number s)))
37- (if (< i 0) (signal (condition '(exn message "nats must be positive")))
39+ (if (< i 0) (parse-error "nats must be positive")
3840 i)))
3941 (define (string->int s)
4042 (let ((i (string->number s))) (if (< i 0) (cons 0 (abs i)) (cons i 0))))
43+(define (string->listof p) (lambda (s)
44+ (let ((len (string-length s)))
45+ (if (not (equal? #\( (string-ref s 0)))
46+ (parse-error "list must start with ("))
47+ (if (not (equal? #\) (string-ref s (- len 1))))
48+ (parse-error "list must end with )"))
49+ (map p (string-split (substring s 1 (- len 1)))))))
50+
4151 (define (fold-left kn kc l) (if (null? l) kn (kc (car l) (fold-left kn kc (cdr l)))))
4252 (define (zip-app fs xs)
4353 (if (null? fs) '()