• 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

修订版5fd12d13873df41116bc348843c73a8384ddc1b1 (tree)
时间2022-07-10 12:56:20
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Specialize (uncurry id) to app.

更改概述

差异

--- a/accept-jelly.json
+++ b/accept-jelly.json
@@ -3,7 +3,7 @@
33 ["(pair X Y)", "X", ["fst"]],
44 ["X", "(pair X X)", ["dup"]],
55 ["(pair X Y)", "(pair Y X)", ["swap"]],
6- ["(pair (hom X Y) X)", "Y", ["(uncurry id)"]],
6+ ["(pair (hom X Y) X)", "Y", ["app"]],
77 ["1", "2", ["t", "f"]],
88 ["1", "(list X)", ["nil", "(comp ignore nil)"]]
99 ]
--- a/cammy-rpy/cammylib/arrows.py
+++ b/cammy-rpy/cammylib/arrows.py
@@ -152,6 +152,20 @@ class Uncurry(Arrow):
152152 cs.unify(fcod, cs.functor("hom", [x, y]))
153153 return cs.functor("pair", [fdom, x]), y
154154
155+class App(Arrow):
156+ _immutable_ = True
157+ def compile(self, compiler):
158+ compiler.push()
159+ compiler.snd()
160+ compiler.swap()
161+ compiler.fst()
162+ # app == (uncurry id); id would go here
163+ compiler.app()
164+ def types(self, cs):
165+ x = cs.fresh()
166+ y = cs.fresh()
167+ return cs.functor("pair", [cs.functor("hom", [x, y]), x]), y
168+
155169 class Either(Arrow):
156170 _immutable_ = True
157171 def compile(self, compiler): compiler.branch()
@@ -392,6 +406,7 @@ unaryFunctors = {
392406 "snd": Second(),
393407 "dup": Dup(),
394408 "swap": Swap(),
409+ "app": App(),
395410 "left": Left(),
396411 "right": Right(),
397412 "either": Either(),
--- a/cammy-rpy/repl.py
+++ b/cammy-rpy/repl.py
@@ -39,12 +39,30 @@ class PlaintextTypeFormatter(TypeFormatter):
3939 class PromptContext(object):
4040 mostRecentExpr = None
4141
42+def printDuration(duration):
43+ unit = "s"
44+ if duration < 1.0:
45+ duration *= 1000
46+ unit = "ms"
47+ if duration < 1.0:
48+ duration *= 1000
49+ unit = "µs"
50+ print "(%f %s)" % (duration, unit)
51+
4252 def printElement(cam):
53+ start = time.time()
4354 print cam.execute(T()).asStr()
55+ printDuration(time.time() - start)
4456
4557 def printSequence(cam):
46- for i in range(5):
58+ start = time.time()
59+ duration = 0.0
60+ for i in range(10):
4761 print i, "|->", cam.execute(N(i)).asStr()
62+ duration = time.time() - start
63+ if duration > 1.0:
64+ break
65+ printDuration(duration)
4866
4967 def command(hive, code, line, context):
5068 # XXX code e: Edit a file
@@ -58,32 +76,20 @@ def command(hive, code, line, context):
5876 cs = ConstraintStore()
5977 domain, codomain = arrow.types(cs)
6078
61- start = time.time()
6279 # If the arrow is polymorphic, monomorphize it.
6380 try:
6481 cs.unify(domain, cs.concrete("1"))
6582 # Compile the arrow and run it.
6683 cam = compileArrow(arrow)
67- start = time.time()
6884 printElement(cam)
6985 except UnificationFailed:
7086 # Maybe it's a sequence?
7187 try:
7288 cs.unify(domain, cs.concrete("N"))
7389 cam = compileArrow(arrow)
74- start = time.time()
7590 printSequence(cam)
7691 except UnificationFailed:
7792 print "Couldn't unify domain with 1 or N, so can't display this element"
78- duration = time.time() - start
79- unit = "s"
80- if duration < 1.0:
81- duration *= 1000
82- unit = "ms"
83- if duration < 1.0:
84- duration *= 1000
85- unit = "µs"
86- print "(%f %s)" % (duration, unit)
8793 elif code == "n":
8894 # Normalize an arrow.
8995 sexp, trail = parse(line)
--- /dev/null
+++ b/hive/advance-lentz-coeffs.cammy
@@ -0,0 +1 @@
1+(comp (pair/tensor (pair/mapfst f-recip) (v2/map (comp nat/to-f dup))) (comp (v2/map2 (comp pair/assl f/mad)) (pair/mapsnd f-recip)))
\ No newline at end of file
--- /dev/null
+++ b/hive/apply-moore-machine.cammy
@@ -0,0 +1 @@
1+(comp (fold (pair nil @0) (pair (pair/of cons (comp sndsnd @1) sndfst) (pair/of @2 sndsnd fst))) fst)
\ No newline at end of file
--- /dev/null
+++ b/hive/f/eq?.cammy
@@ -0,0 +1 @@
1+(comp (pair/of disj f-lt (comp swap f-lt)) not)
\ No newline at end of file
--- /dev/null
+++ b/hive/f/inf.cammy
@@ -0,0 +1 @@
1+(comp f-zero f-recip)
--- /dev/null
+++ b/hive/f/mad.cammy
@@ -0,0 +1 @@
1+(comp (pair/mapfst f-mul) f-add)
\ No newline at end of file
--- /dev/null
+++ b/hive/f/product.cammy
@@ -0,0 +1 @@
1+(fold f-one f-mul)
\ No newline at end of file
--- /dev/null
+++ b/hive/list/drop.cammy
@@ -0,0 +1 @@
1+(pr (fun/name id) (curry (comp (pair/mapsnd (comp list/uncons (case snd nil))) app)))
\ No newline at end of file
--- /dev/null
+++ b/hive/nat/para.cammy
@@ -0,0 +1 @@
1+(comp (pr (pair @0 zero) (pair @1 (comp snd succ))) fst)
\ No newline at end of file
--- /dev/null
+++ b/hive/odd-numbers.cammy
@@ -0,0 +1 @@
1+(comp nat/double succ)
\ No newline at end of file
--- /dev/null
+++ b/hive/v2/complex/add.cammy
@@ -0,0 +1 @@
1+(v2/map2 f-add)
\ No newline at end of file
--- /dev/null
+++ b/hive/v2/complex/one.cammy
@@ -0,0 +1 @@
1+(pair f-one f-zero)
\ No newline at end of file
--- /dev/null
+++ b/hive/v2/complex/zero.cammy
@@ -0,0 +1 @@
1+(pair f-zero f-zero)
\ No newline at end of file
--- /dev/null
+++ b/hive/with-default.cammy
@@ -0,0 +1 @@
1+(comp @0 (case id @1))
\ No newline at end of file
--- a/jelly/src/main.rs
+++ b/jelly/src/main.rs
@@ -141,13 +141,15 @@ fn main() -> std::io::Result<()> {
141141 rw!("curry-uncurry-cancel"; "(uncurry (curry ?f))" => "?f"),
142142 rw!("uncurry-curry-cancel"; "(curry (uncurry ?f))" => "?f"),
143143
144- rw!("beta-full"; "(comp (pair (comp ?x (curry ?f)) ?y) (uncurry id))" => "(comp (pair ?x ?y) ?f)"),
144+ // jet for app
145+ rw!("app-jet"; "(uncurry id)" => "app"),
146+ rw!("beta-full"; "(comp (pair (comp ?x (curry ?f)) ?y) app)" => "(comp (pair ?x ?y) ?f)"),
145147 // Cousineau, Curien, & Mauny 1987
146148 // beta-full when ?x is id
147- rw!("beta"; "(comp (pair (curry ?f) ?y) (uncurry id))" => "(comp (pair id ?y) ?f)"),
149+ rw!("beta"; "(comp (pair (curry ?f) ?y) app)" => "(comp (pair id ?y) ?f)"),
148150 // Hagino 1987
149151 // This is a more powerful form of beta when ?x is (uncurry ...)
150- rw!("beta-fuse"; "(comp (pair ?x ?y) (uncurry ?f))" => "(comp (pair (comp ?x ?f) ?y) (uncurry id))"),
152+ rw!("beta-fuse"; "(comp (pair ?x ?y) (uncurry ?f))" => "(comp (pair (comp ?x ?f) ?y) app)"),
151153
152154 rw!("curry-const"; "(comp ?f (curry (comp fst ?g)))" => "(curry (comp fst (comp ?f ?g)))"),
153155 // curry-const when ?g is id
@@ -162,7 +164,7 @@ fn main() -> std::io::Result<()> {
162164 rw!("nat-shift-pr-endo"; "(comp (pr ?x ?f) ?f)" => "(pr (comp ?x ?f) ?f)"),
163165
164166 // jet for nat/add
165- rw!("nat-add-jet"; "(pr (curry snd) (curry (comp (uncurry id) succ)))" => "(curry n-add)"),
167+ rw!("nat-add-jet"; "(pr (curry snd) (curry (comp app succ)))" => "(curry n-add)"),
166168 // jet for nat/pred-maybe
167169 rw!("nat-pred-maybe-jet"; "(pr right (comp (case succ zero) left))" => "n-pred-maybe"),
168170