summaryrefslogtreecommitdiff
path: root/demo/list.ur
diff options
context:
space:
mode:
authorBenjamin Barenblat <bbaren@mit.edu>2017-07-23 09:50:04 -0400
committerBenjamin Barenblat <bbaren@mit.edu>2017-07-23 09:50:04 -0400
commit0cccdb0ae595cd7e3e136e984ac7b95b99f71a53 (patch)
tree491d3b13813610943c60460d3e178d3a73916346 /demo/list.ur
Import urweb_20170720+dfsg.orig.tar.gz
[dgit import orig urweb_20170720+dfsg.orig.tar.gz]
Diffstat (limited to 'demo/list.ur')
-rw-r--r--demo/list.ur21
1 files changed, 21 insertions, 0 deletions
diff --git a/demo/list.ur b/demo/list.ur
new file mode 100644
index 0000000..961708e
--- /dev/null
+++ b/demo/list.ur
@@ -0,0 +1,21 @@
+datatype list t = Nil | Cons of t * list t
+
+fun length [t] (ls : list t) =
+ let
+ fun length' (ls : list t) (acc : int) =
+ case ls of
+ Nil => acc
+ | Cons (_, ls') => length' ls' (acc + 1)
+ in
+ length' ls 0
+ end
+
+fun rev [t] (ls : list t) =
+ let
+ fun rev' (ls : list t) (acc : list t) =
+ case ls of
+ Nil => acc
+ | Cons (x, ls') => rev' ls' (Cons (x, acc))
+ in
+ rev' ls Nil
+ end