• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

A categorical programming language


Commit MetaInfo

修订版8f46d9690f137bd171003b4d4754d017a75b9b81 (tree)
时间2021-08-14 09:19:57
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Add map() functor on lists.

A little bit of abstract thought suggests that fold() isn't enough to do
this, but I'm very open to constructive proofs otherwise.

更改概述

差异

--- a/cammy.txt
+++ b/cammy.txt
@@ -50,6 +50,7 @@ Given x : 1 → X and f : X → X, pr(x, f) : N → X
5050
5151 nil : 1 → [X]
5252 cons : X × [X] → X
53+Given f : X → Y, map(f) : [X] → [Y]
5354 Given x : 1 → Y and f : X × Y → Y, fold(x, f) : [X] → Y
5455
5556 Combinators with (*) are provided by OCaml by default; the others are in a
--- a/finish.py
+++ b/finish.py
@@ -26,6 +26,7 @@ with open("stub.scm", "r", encoding="utf-8") as handle:
2626 with open(sys.argv[-2], "r", encoding="utf-8") as handle:
2727 program = handle.read().strip()
2828 program = program.replace("cons", "cammy-cons")
29+ program = program.replace("map", "cammy-map")
2930 print("(define program {})".format(program))
3031
3132 print("""
--- a/frame/frame.ml
+++ b/frame/frame.ml
@@ -4,7 +4,7 @@ module CodeCache = Map.Make (String)
44
55 let primitives =
66 "id comp ignore fst snd pair left right case assl assr swap dup curry \
7- uncurry app name zero succ for nil cons fold t f not conj disj"
7+ uncurry app name zero succ for nil cons map fold t f not conj disj"
88
99 let filter =
1010 List.fold_left
--- /dev/null
+++ b/hive/bool/is_left.cammy
@@ -0,0 +1 @@
1+(case (comp ignore t) (comp ignore f))
--- a/stub.ml
+++ b/stub.ml
@@ -25,4 +25,5 @@ let succ n = S n
2525 let rec pr x f n = match n with O -> x () | S p -> f (pr x f p)
2626 let nil () = []
2727 let cons (x, xs) = x :: xs
28+let map f = List.map f
2829 let fold x f = List.fold_left (fun y z -> f (z, y)) (x ())
--- a/stub.scm
+++ b/stub.scm
@@ -30,6 +30,7 @@
3030
3131 (define nil (lambda (x) '()))
3232 (define cammy-cons (lambda (xy) (cons (car xy) (cdr xy))))
33+(define (cammy-map f) (lambda (l) (map f l)))
3334 (define (fold x f)
3435 (lambda (l) (if (null? l) (x '()) (f (cons (car l) ((fold x f) (cdr l)))))))
3536
--- a/todo.txt
+++ b/todo.txt
@@ -1,5 +1,4 @@
11 * list/eq : [X × X, 2] → [[X] × [X], 2]
22 * list/zip : [X] × [Y] → [X × Y]
3-* list/map : [X, Y] → [[X], [Y]]
43 * list/tail : [X] → [X]
54 * rat