summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-10-21 19:24:39 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-10-21 19:24:39 -0400
commit17b3f5af99c07d7361fb99124412aff1768cfe13 (patch)
treefcfbcfaf492be1aa13c484eea28cfedaf565ed6c /lib
parentd66bb9f256db65e3487dec361a4a5a9d7ee238b0 (diff)
Sum demo, minus inference of {Unit}s
Diffstat (limited to 'lib')
-rw-r--r--lib/top.ur14
-rw-r--r--lib/top.urs9
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/top.ur b/lib/top.ur
index bdf5f182..9ba26068 100644
--- a/lib/top.ur
+++ b/lib/top.ur
@@ -6,6 +6,9 @@ con sndTT (t :: (Type * Type)) = t.2
con mapTT (f :: Type -> Type) = fold (fn nm t acc [[nm] ~ acc] =>
[nm = f t] ++ acc) []
+con mapUT = fn f :: Type => fold (fn nm t acc [[nm] ~ acc] =>
+ [nm = f] ++ acc) []
+
con mapT2T (f :: (Type * Type) -> Type) = fold (fn nm t acc [[nm] ~ acc] =>
[nm = f t] ++ acc) []
@@ -22,6 +25,17 @@ fun compose (t1 ::: Type) (t2 ::: Type) (t3 ::: Type)
fun txt (t ::: Type) (ctx ::: {Unit}) (use ::: {Type}) (sh : show t) (v : t) =
cdata (@show sh v)
+fun foldUR (tf :: Type) (tr :: {Unit} -> Type)
+ (f : nm :: Name -> rest :: {Unit}
+ -> fn [[nm] ~ rest] =>
+ tf -> tr rest -> tr ([nm] ++ rest))
+ (i : tr []) =
+ fold [fn r :: {Unit} => $(mapUT tf r) -> tr r]
+ (fn (nm :: Name) (t :: Unit) (rest :: {Unit}) (acc : $(mapUT tf rest) -> tr rest)
+ [[nm] ~ rest] (r : $([nm = tf] ++ mapUT tf rest)) =>
+ f [nm] [rest] r.nm (acc (r -- nm)))
+ (fn _ => i)
+
fun foldTR (tf :: Type -> Type) (tr :: {Type} -> Type)
(f : nm :: Name -> t :: Type -> rest :: {Type}
-> fn [[nm] ~ rest] =>
diff --git a/lib/top.urs b/lib/top.urs
index bf26d534..abdb7477 100644
--- a/lib/top.urs
+++ b/lib/top.urs
@@ -6,6 +6,9 @@ con sndTT = fn t :: (Type * Type) => t.2
con mapTT = fn f :: Type -> Type => fold (fn nm t acc [[nm] ~ acc] =>
[nm = f t] ++ acc) []
+con mapUT = fn f :: Type => fold (fn nm t acc [[nm] ~ acc] =>
+ [nm = f] ++ acc) []
+
con mapT2T = fn f :: (Type * Type) -> Type => fold (fn nm t acc [[nm] ~ acc] =>
[nm = f t] ++ acc) []
@@ -20,6 +23,12 @@ val compose : t1 ::: Type -> t2 ::: Type -> t3 ::: Type
val txt : t ::: Type -> ctx ::: {Unit} -> use ::: {Type} -> show t -> t
-> xml ctx use []
+val foldUR : tf :: Type -> tr :: ({Unit} -> Type)
+ -> (nm :: Name -> rest :: {Unit}
+ -> fn [[nm] ~ rest] =>
+ tf -> tr rest -> tr ([nm] ++ rest))
+ -> tr [] -> r :: {Unit} -> $(mapUT tf r) -> tr r
+
val foldTR : tf :: (Type -> Type) -> tr :: ({Type} -> Type)
-> (nm :: Name -> t :: Type -> rest :: {Type}
-> fn [[nm] ~ rest] =>