summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/js/urweb.js18
-rw-r--r--lib/ur/monad.ur35
-rw-r--r--lib/ur/monad.urs24
-rw-r--r--lib/ur/top.ur12
-rw-r--r--lib/ur/top.urs6
5 files changed, 83 insertions, 12 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 57ad5454..ef2c7b49 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -306,7 +306,7 @@ function dyn(pnode, s) {
var arr = dummy.getElementsByTagName("tbody");
firstChild = null;
- if (arr.length > 0) {
+ if (arr.length > 0 && table != null) {
var tbody = arr[0], next;
firstChild = document.createElement("script");
table.insertBefore(firstChild, x);
@@ -323,7 +323,7 @@ function dyn(pnode, s) {
var arr = dummy.getElementsByTagName("tr");
firstChild = null;
- if (arr.length > 0) {
+ if (arr.length > 0 && table != null) {
var tbody = arr[0], next;
firstChild = document.createElement("script");
table.insertBefore(firstChild, x);
@@ -468,7 +468,19 @@ function uf(s) {
}
function uu(s) {
- return unescape(s);
+ return unescape(s.replace(new RegExp ("\\+", "g"), " "));
+}
+
+function uul(getToken, getData) {
+ var tok = getToken();
+ if (tok == "Nil") {
+ return null;
+ } else if (tok == "Cons") {
+ var d = getData();
+ var l = uul(getToken, getData);
+ return {_1:d, _2:l};
+ } else
+ throw ("Can't unmarshal list (" + tok + ")");
}
diff --git a/lib/ur/monad.ur b/lib/ur/monad.ur
index 73001094..356173fd 100644
--- a/lib/ur/monad.ur
+++ b/lib/ur/monad.ur
@@ -7,3 +7,38 @@ fun exec [m ::: Type -> Type] (_ : monad m) [ts ::: {Type}] r (fd : folder ts) =
(return {}) [ts] fd r
fun ignore [m ::: Type -> Type] (_ : monad m) [t] (v : m t) = x <- v; return ()
+
+fun foldR [K] [m] (_ : monad m) [tf :: K -> Type] [tr :: {K} -> Type]
+ (f : nm :: Name -> t :: K -> rest :: {K}
+ -> [[nm] ~ rest] =>
+ tf t -> tr rest -> m (tr ([nm = t] ++ rest)))
+ (i : tr []) [r :: {K}] (fl : folder r) =
+ Top.fold [fn r :: {K} => $(map tf r) -> m (tr r)]
+ (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
+ (acc : _ -> m (tr rest)) r =>
+ acc' <- acc (r -- nm);
+ f [nm] [t] [rest] ! r.nm acc')
+ (fn _ => return i)
+ [_] fl
+
+fun foldR2 [K] [m] (_ : monad m) [tf1 :: K -> Type] [tf2 :: K -> Type] [tr :: {K} -> Type]
+ (f : nm :: Name -> t :: K -> rest :: {K}
+ -> [[nm] ~ rest] =>
+ tf1 t -> tf2 t -> tr rest -> m (tr ([nm = t] ++ rest)))
+ (i : tr []) [r :: {K}] (fl : folder r) =
+ Top.fold [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> m (tr r)]
+ (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
+ (acc : _ -> _ -> m (tr rest)) r1 r2 =>
+ acc' <- acc (r1 -- nm) (r2 -- nm);
+ f [nm] [t] [rest] ! r1.nm r2.nm acc')
+ (fn _ _ => return i)
+ [_] fl
+
+fun mapR [K] [m] (_ : monad m) [tf :: K -> Type] [tr :: K -> Type]
+ (f : nm :: Name -> t :: K -> tf t -> m (tr t)) =
+ @@foldR [m] _ [tf] [fn r => $(map tr r)]
+ (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] (v : tf t)
+ (acc : $(map tr rest)) =>
+ v' <- f [nm] [t] v;
+ return (acc ++ {nm = v'}))
+ {}
diff --git a/lib/ur/monad.urs b/lib/ur/monad.urs
index b3cb3d6f..662d780f 100644
--- a/lib/ur/monad.urs
+++ b/lib/ur/monad.urs
@@ -3,3 +3,27 @@ val exec : m ::: (Type -> Type) -> monad m -> ts ::: {Type}
val ignore : m ::: (Type -> Type) -> monad m -> t ::: Type
-> m t -> m unit
+
+val foldR : K --> m ::: (Type -> Type) -> monad m
+ -> tf :: (K -> Type)
+ -> tr :: ({K} -> Type)
+ -> (nm :: Name -> t :: K -> rest :: {K}
+ -> [[nm] ~ rest] =>
+ tf t -> tr rest -> m (tr ([nm = t] ++ rest)))
+ -> tr []
+ -> r :: {K} -> folder r -> $(map tf r) -> m (tr r)
+
+val foldR2 : K --> m ::: (Type -> Type) -> monad m
+ -> tf1 :: (K -> Type) -> tf2 :: (K -> Type)
+ -> tr :: ({K} -> Type)
+ -> (nm :: Name -> t :: K -> rest :: {K}
+ -> [[nm] ~ rest] =>
+ tf1 t -> tf2 t -> tr rest -> m (tr ([nm = t] ++ rest)))
+ -> tr []
+ -> r :: {K} -> folder r -> $(map tf1 r) -> $(map tf2 r) -> m (tr r)
+
+val mapR : K --> m ::: (Type -> Type) -> monad m
+ -> tf :: (K -> Type)
+ -> tr :: (K -> Type)
+ -> (nm :: Name -> t :: K -> tf t -> m (tr t))
+ -> r :: {K} -> folder r -> $(map tf r) -> m ($(map tr r))
diff --git a/lib/ur/top.ur b/lib/ur/top.ur
index 3dac7ff0..ce110b27 100644
--- a/lib/ur/top.ur
+++ b/lib/ur/top.ur
@@ -98,12 +98,12 @@ fun mp [K] [tf1 :: K -> Type] [tf2 :: K -> Type] (f : t ::: K -> tf1 t -> tf2 t)
acc (r -- nm) ++ {nm = f r.nm})
(fn _ => {})
-fun map2 [K1] [K2] [tf1 :: K1 -> Type] [tf2 :: K2 -> Type] [tf :: K1 -> K2]
- (f : t ::: K1 -> tf1 t -> tf2 (tf t)) [r :: {K1}] (fl : folder r) =
- fl [fn r :: {K1} => $(map tf1 r) -> $(map tf2 (map tf r))]
- (fn [nm :: Name] [t :: K1] [rest :: {K1}] [[nm] ~ rest] acc r =>
- acc (r -- nm) ++ {nm = f r.nm})
- (fn _ => {})
+fun map2 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type]
+ (f : t ::: K -> tf1 t -> tf2 t -> tf3 t) [r :: {K}] (fl : folder r) =
+ fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r)]
+ (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] acc r1 r2 =>
+ acc (r1 -- nm) (r2 -- nm) ++ {nm = f r1.nm r2.nm})
+ (fn _ _ => {})
fun foldUR [tf :: Type] [tr :: {Unit} -> Type]
(f : nm :: Name -> rest :: {Unit}
diff --git a/lib/ur/top.urs b/lib/ur/top.urs
index 33c90651..bdf9d904 100644
--- a/lib/ur/top.urs
+++ b/lib/ur/top.urs
@@ -48,9 +48,9 @@ val txt : t ::: Type -> ctx ::: {Unit} -> use ::: {Type} -> show t -> t
val mp : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type)
-> (t ::: K -> tf1 t -> tf2 t)
-> r :: {K} -> folder r -> $(map tf1 r) -> $(map tf2 r)
-val map2 : K1 --> K2 --> tf1 :: (K1 -> Type) -> tf2 :: (K2 -> Type) -> tf :: (K1 -> K2)
- -> (t ::: K1 -> tf1 t -> tf2 (tf t))
- -> r :: {K1} -> folder r -> $(map tf1 r) -> $(map tf2 (map tf r))
+val map2 : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type) -> tf3 :: (K -> Type)
+ -> (t ::: K -> tf1 t -> tf2 t -> tf3 t)
+ -> r :: {K} -> folder r -> $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r)
val foldUR : tf :: Type -> tr :: ({Unit} -> Type)
-> (nm :: Name -> rest :: {Unit}