summaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-10-23 12:58:35 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-10-23 12:58:35 -0400
commit2e606b03c8dbc594610e62ac260145ac26ebc699 (patch)
tree23055572341487865f0ef6cff685404f796a2410 /demo
parent3b7e65be5f6e496c23df7909d50ce8e287d571d7 (diff)
Fix nasty de Bruijn substitution bug; TcSum demo
Diffstat (limited to 'demo')
-rw-r--r--demo/prose4
-rw-r--r--demo/tcSum.ur9
-rw-r--r--demo/tcSum.urp2
-rw-r--r--demo/tcSum.urs1
4 files changed, 16 insertions, 0 deletions
diff --git a/demo/prose b/demo/prose
index 8fedc557..19e9df0f 100644
--- a/demo/prose
+++ b/demo/prose
@@ -100,3 +100,7 @@ An unusual part of the third argument is the syntax <tt>[t1 ~ t2]</tt> within a
<p>The general syntax for constant row types is <tt>[Name1 = t1, ..., NameN = tN]</tt>, and there is a shorthand version <tt>[Name1, ..., NameN]</tt> for records of <tt>Unit</tt>s.</p>
<p>With <tt>sum</tt> defined, it is easy to make some sample calls. The form of the code for <tt>main</tt> does not make it apparent, but the compiler must "reverse engineer" the appropriate <tt>{Unit}</tt> from the <tt>{Type}</tt> available from the context at each call to <tt>sum</tt>.</p>
+
+tcSum.urp
+
+<p>It's easy to adapt the last example to use type classes, such that we can sum the fields of records based on any numeric type.</p>
diff --git a/demo/tcSum.ur b/demo/tcSum.ur
new file mode 100644
index 00000000..53679116
--- /dev/null
+++ b/demo/tcSum.ur
@@ -0,0 +1,9 @@
+fun sum (t ::: Type) (_ : num t) (fs ::: {Unit}) (x : $(mapUT t fs)) =
+ foldUR [t] [fn _ => t]
+ (fn (nm :: Name) (rest :: {Unit}) [[nm] ~ rest] n acc => n + acc)
+ zero [fs] x
+
+fun main () = return <xml><body>
+ {[sum {A = 0, B = 1}]}<br/>
+ {[sum {C = 2.1, D = 3.2, E = 4.3}]}
+</body></xml>
diff --git a/demo/tcSum.urp b/demo/tcSum.urp
new file mode 100644
index 00000000..8b36efc0
--- /dev/null
+++ b/demo/tcSum.urp
@@ -0,0 +1,2 @@
+
+tcSum
diff --git a/demo/tcSum.urs b/demo/tcSum.urs
new file mode 100644
index 00000000..6ac44e0b
--- /dev/null
+++ b/demo/tcSum.urs
@@ -0,0 +1 @@
+val main : unit -> transaction page