summaryrefslogtreecommitdiff
path: root/lib/ur
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-02-22 16:10:25 -0500
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-02-22 16:10:25 -0500
commit85cf99a95c910841f197ca911bb13d044456de7f (patch)
tree7f9fc4189681a0186e8ecbfcc84a0eec50d03be9 /lib/ur
parentc60437564b5265a6f0735bd402abead87782d36a (diff)
Start of kind polymorphism, up to the point where demo/hello elaborates with updated Basis/Top
Diffstat (limited to 'lib/ur')
-rw-r--r--lib/ur/top.ur171
-rw-r--r--lib/ur/top.urs112
2 files changed, 78 insertions, 205 deletions
diff --git a/lib/ur/top.ur b/lib/ur/top.ur
index 58e99f3c..9016fd27 100644
--- a/lib/ur/top.ur
+++ b/lib/ur/top.ur
@@ -1,3 +1,12 @@
+(** Row folding *)
+
+con folder = K ==> fn r :: {K} =>
+ tf :: ({K} -> Type)
+ -> (nm :: Name -> v :: K -> r :: {K} -> tf r
+ -> fn [[nm] ~ r] => tf ([nm = v] ++ r))
+ -> tf [] -> tf r
+
+
fun not b = if b then False else True
con idT (t :: Type) = t
@@ -27,23 +36,23 @@ fun foldUR (tf :: Type) (tr :: {Unit} -> Type)
(f : nm :: Name -> rest :: {Unit}
-> fn [[nm] ~ rest] =>
tf -> tr rest -> tr ([nm] ++ rest))
- (i : tr []) =
+ (i : tr []) (r ::: {Unit}) (fold : folder r)=
fold [fn r :: {Unit} => $(mapUT tf r) -> tr r]
- (fn (nm :: Name) (t :: Unit) (rest :: {Unit}) acc
- [[nm] ~ rest] r =>
- f [nm] [rest] r.nm (acc (r -- nm)))
- (fn _ => i)
+ (fn (nm :: Name) (t :: Unit) (rest :: {Unit}) acc
+ [[nm] ~ rest] r =>
+ f [nm] [rest] r.nm (acc (r -- nm)))
+ (fn _ => i)
fun foldUR2 (tf1 :: Type) (tf2 :: Type) (tr :: {Unit} -> Type)
(f : nm :: Name -> rest :: {Unit}
-> fn [[nm] ~ rest] =>
tf1 -> tf2 -> tr rest -> tr ([nm] ++ rest))
- (i : tr []) =
+ (i : tr []) (r ::: {Unit}) (fold : folder r) =
fold [fn r :: {Unit} => $(mapUT tf1 r) -> $(mapUT tf2 r) -> tr r]
- (fn (nm :: Name) (t :: Unit) (rest :: {Unit}) acc
- [[nm] ~ rest] r1 r2 =>
- f [nm] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
- (fn _ _ => i)
+ (fn (nm :: Name) (t :: Unit) (rest :: {Unit}) acc
+ [[nm] ~ rest] r1 r2 =>
+ f [nm] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
+ (fn _ _ => i)
fun foldURX2 (tf1 :: Type) (tf2 :: Type) (ctx :: {Unit})
(f : nm :: Name -> rest :: {Unit}
@@ -54,134 +63,46 @@ fun foldURX2 (tf1 :: Type) (tf2 :: Type) (ctx :: {Unit})
<xml>{f [nm] [rest] v1 v2}{acc}</xml>)
<xml/>
-fun foldTR (tf :: Type -> Type) (tr :: {Type} -> Type)
- (f : nm :: Name -> t :: Type -> rest :: {Type}
+fun foldR K (tf :: K -> Type) (tr :: {K} -> Type)
+ (f : nm :: Name -> t :: K -> rest :: {K}
-> fn [[nm] ~ rest] =>
tf t -> tr rest -> tr ([nm = t] ++ rest))
- (i : tr []) =
- fold [fn r :: {Type} => $(map tf r) -> tr r]
- (fn (nm :: Name) (t :: Type) (rest :: {Type}) (acc : _ -> tr rest)
+ (i : tr []) (r ::: {K}) (fold : folder r) =
+ fold [fn r :: {K} => $(map tf r) -> tr r]
+ (fn (nm :: Name) (t :: K) (rest :: {K}) (acc : _ -> tr rest)
[[nm] ~ rest] r =>
f [nm] [t] [rest] r.nm (acc (r -- nm)))
(fn _ => i)
-fun foldT2R (tf :: (Type * Type) -> Type) (tr :: {(Type * Type)} -> Type)
- (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf t -> tr rest -> tr ([nm = t] ++ rest))
- (i : tr []) =
- fold [fn r :: {(Type * Type)} => $(map tf r) -> tr r]
- (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
- (acc : _ -> tr rest) [[nm] ~ rest] r =>
- f [nm] [t] [rest] r.nm (acc (r -- nm)))
- (fn _ => i)
-
-fun foldT3R (tf :: (Type * Type * Type) -> Type) (tr :: {(Type * Type * Type)} -> Type)
- (f : nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf t -> tr rest -> tr ([nm = t] ++ rest))
- (i : tr []) =
- fold [fn r :: {(Type * Type * Type)} => $(map tf r) -> tr r]
- (fn (nm :: Name) (t :: (Type * Type * Type)) (rest :: {(Type * Type * Type)})
- (acc : _ -> tr rest) [[nm] ~ rest] r =>
- f [nm] [t] [rest] r.nm (acc (r -- nm)))
- (fn _ => i)
-
-fun foldTR2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (tr :: {Type} -> Type)
- (f : nm :: Name -> t :: Type -> rest :: {Type}
+fun foldR2 K (tf1 :: K -> Type) (tf2 :: K -> Type) (tr :: {K} -> Type)
+ (f : nm :: Name -> t :: K -> rest :: {K}
-> fn [[nm] ~ rest] =>
tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
- (i : tr []) =
- fold [fn r :: {Type} => $(map tf1 r) -> $(map tf2 r) -> tr r]
- (fn (nm :: Name) (t :: Type) (rest :: {Type})
- (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 =>
- f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
- (fn _ _ => i)
-
-fun foldT2R2 (tf1 :: (Type * Type) -> Type) (tf2 :: (Type * Type) -> Type)
- (tr :: {(Type * Type)} -> Type)
- (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
- (i : tr []) =
- fold [fn r :: {(Type * Type)} => $(map tf1 r) -> $(map tf2 r) -> tr r]
- (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
- (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 =>
- f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
- (fn _ _ => i)
-
-fun foldT3R2 (tf1 :: (Type * Type * Type) -> Type) (tf2 :: (Type * Type * Type) -> Type)
- (tr :: {(Type * Type * Type)} -> Type)
- (f : nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
- (i : tr []) =
- fold [fn r :: {(Type * Type * Type)} => $(map tf1 r) -> $(map tf2 r) -> tr r]
- (fn (nm :: Name) (t :: (Type * Type * Type)) (rest :: {(Type * Type * Type)})
- (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 =>
- f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
- (fn _ _ => i)
-
-fun foldTRX (tf :: Type -> Type) (ctx :: {Unit})
- (f : nm :: Name -> t :: Type -> rest :: {Type}
+ (i : tr []) (r ::: {K}) (fold : folder r) =
+ fold [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> tr r]
+ (fn (nm :: Name) (t :: K) (rest :: {K})
+ (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 =>
+ f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
+ (fn _ _ => i)
+
+fun foldRX K (tf :: K -> Type) (ctx :: {Unit})
+ (f : nm :: Name -> t :: K -> rest :: {K}
-> fn [[nm] ~ rest] =>
tf t -> xml ctx [] []) =
- foldTR [tf] [fn _ => xml ctx [] []]
- (fn (nm :: Name) (t :: Type) (rest :: {Type}) [[nm] ~ rest] r acc =>
- <xml>{f [nm] [t] [rest] r}{acc}</xml>)
- <xml/>
-
-fun foldT2RX (tf :: (Type * Type) -> Type) (ctx :: {Unit})
- (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf t -> xml ctx [] []) =
- foldT2R [tf] [fn _ => xml ctx [] []]
- (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
- [[nm] ~ rest] r acc =>
- <xml>{f [nm] [t] [rest] r}{acc}</xml>)
- <xml/>
-
-fun foldT3RX (tf :: (Type * Type * Type) -> Type) (ctx :: {Unit})
- (f : nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf t -> xml ctx [] []) =
- foldT3R [tf] [fn _ => xml ctx [] []]
- (fn (nm :: Name) (t :: (Type * Type * Type)) (rest :: {(Type * Type * Type)})
- [[nm] ~ rest] r acc =>
- <xml>{f [nm] [t] [rest] r}{acc}</xml>)
- <xml/>
+ foldR [tf] [fn _ => xml ctx [] []]
+ (fn (nm :: Name) (t :: K) (rest :: {K}) [[nm] ~ rest] r acc =>
+ <xml>{f [nm] [t] [rest] r}{acc}</xml>)
+ <xml/>
-fun foldTRX2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (ctx :: {Unit})
- (f : nm :: Name -> t :: Type -> rest :: {Type}
+fun foldRX2 K (tf1 :: K -> Type) (tf2 :: K -> Type) (ctx :: {Unit})
+ (f : nm :: Name -> t :: K -> rest :: {K}
-> fn [[nm] ~ rest] =>
tf1 t -> tf2 t -> xml ctx [] []) =
- foldTR2 [tf1] [tf2] [fn _ => xml ctx [] []]
- (fn (nm :: Name) (t :: Type) (rest :: {Type}) [[nm] ~ rest]
- r1 r2 acc =>
- <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>)
- <xml/>
-
-fun foldT2RX2 (tf1 :: (Type * Type) -> Type) (tf2 :: (Type * Type) -> Type)
- (ctx :: {Unit})
- (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf1 t -> tf2 t -> xml ctx [] []) =
- foldT2R2 [tf1] [tf2] [fn _ => xml ctx [] []]
- (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
- [[nm] ~ rest] r1 r2 acc =>
- <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>)
- <xml/>
-
-fun foldT3RX2 (tf1 :: (Type * Type * Type) -> Type) (tf2 :: (Type * Type * Type) -> Type)
- (ctx :: {Unit})
- (f : nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf1 t -> tf2 t -> xml ctx [] []) =
- foldT3R2 [tf1] [tf2] [fn _ => xml ctx [] []]
- (fn (nm :: Name) (t :: (Type * Type * Type)) (rest :: {(Type * Type * Type)})
- [[nm] ~ rest] r1 r2 acc =>
- <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>)
- <xml/>
+ foldR2 [tf1] [tf2] [fn _ => xml ctx [] []]
+ (fn (nm :: Name) (t :: K) (rest :: {K}) [[nm] ~ rest]
+ r1 r2 acc =>
+ <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>)
+ <xml/>
fun queryX (tables ::: {{Type}}) (exps ::: {Type}) (ctx ::: {Unit})
(q : sql_query tables exps) [tables ~ exps]
diff --git a/lib/ur/top.urs b/lib/ur/top.urs
index 49aad50c..d891c80d 100644
--- a/lib/ur/top.urs
+++ b/lib/ur/top.urs
@@ -1,3 +1,12 @@
+(** Row folding *)
+
+con folder = K ==> fn r :: {K} =>
+ tf :: ({K} -> Type)
+ -> (nm :: Name -> v :: K -> r :: {K} -> tf r
+ -> fn [[nm] ~ r] => tf ([nm = v] ++ r))
+ -> tf [] -> tf r
+
+
val not : bool -> bool
con idT = fn t :: Type => t
@@ -25,103 +34,46 @@ 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
+ -> tr [] -> r ::: {Unit} -> folder r -> $(mapUT tf r) -> tr r
val foldUR2 : tf1 :: Type -> tf2 :: Type -> tr :: ({Unit} -> Type)
-> (nm :: Name -> rest :: {Unit}
-> fn [[nm] ~ rest] =>
tf1 -> tf2 -> tr rest -> tr ([nm] ++ rest))
- -> tr [] -> r :: {Unit} -> $(mapUT tf1 r) -> $(mapUT tf2 r) -> tr r
+ -> tr [] -> r ::: {Unit} -> folder r -> $(mapUT tf1 r) -> $(mapUT tf2 r) -> tr r
val foldURX2: tf1 :: Type -> tf2 :: Type -> ctx :: {Unit}
-> (nm :: Name -> rest :: {Unit}
-> fn [[nm] ~ rest] =>
tf1 -> tf2 -> xml ctx [] [])
- -> r :: {Unit} -> $(mapUT tf1 r) -> $(mapUT tf2 r) -> xml ctx [] []
+ -> r ::: {Unit} -> folder r -> $(mapUT tf1 r) -> $(mapUT tf2 r) -> xml ctx [] []
-val foldTR : tf :: (Type -> Type) -> tr :: ({Type} -> Type)
- -> (nm :: Name -> t :: Type -> rest :: {Type}
+val foldR : K --> tf :: (K -> Type) -> tr :: ({K} -> Type)
+ -> (nm :: Name -> t :: K -> rest :: {K}
-> fn [[nm] ~ rest] =>
tf t -> tr rest -> tr ([nm = t] ++ rest))
- -> tr [] -> r :: {Type} -> $(map tf r) -> tr r
+ -> tr [] -> r ::: {K} -> folder r -> $(map tf r) -> tr r
-val foldT2R : tf :: ((Type * Type) -> Type) -> tr :: ({(Type * Type)} -> Type)
- -> (nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf t -> tr rest -> tr ([nm = t] ++ rest))
- -> tr [] -> r :: {(Type * Type)} -> $(map tf r) -> tr r
+val foldR2 : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type)
+ -> tr :: ({K} -> Type)
+ -> (nm :: Name -> t :: K -> rest :: {K}
+ -> fn [[nm] ~ rest] =>
+ tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
+ -> tr []
+ -> r ::: {K} -> folder r -> $(map tf1 r) -> $(map tf2 r) -> tr r
-val foldT3R : tf :: ((Type * Type * Type) -> Type) -> tr :: ({(Type * Type * Type)} -> Type)
- -> (nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf t -> tr rest -> tr ([nm = t] ++ rest))
- -> tr [] -> r :: {(Type * Type * Type)} -> $(map tf r) -> tr r
+val foldRX : K --> tf :: (K -> Type) -> ctx :: {Unit}
+ -> (nm :: Name -> t :: K -> rest :: {K}
+ -> fn [[nm] ~ rest] =>
+ tf t -> xml ctx [] [])
+ -> r ::: {K} -> folder r -> $(map tf r) -> xml ctx [] []
-val foldTR2 : tf1 :: (Type -> Type) -> tf2 :: (Type -> Type)
- -> tr :: ({Type} -> Type)
- -> (nm :: Name -> t :: Type -> rest :: {Type}
- -> fn [[nm] ~ rest] =>
- tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
- -> tr []
- -> r :: {Type} -> $(map tf1 r) -> $(map tf2 r) -> tr r
-
-val foldT2R2 : tf1 :: ((Type * Type) -> Type) -> tf2 :: ((Type * Type) -> Type)
- -> tr :: ({(Type * Type)} -> Type)
- -> (nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
- -> tr [] -> r :: {(Type * Type)}
- -> $(map tf1 r) -> $(map tf2 r) -> tr r
-
-val foldT3R2 : tf1 :: ((Type * Type * Type) -> Type) -> tf2 :: ((Type * Type * Type) -> Type)
- -> tr :: ({(Type * Type * Type)} -> Type)
- -> (nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
- -> tr [] -> r :: {(Type * Type * Type)}
- -> $(map tf1 r) -> $(map tf2 r) -> tr r
-
-val foldTRX : tf :: (Type -> Type) -> ctx :: {Unit}
- -> (nm :: Name -> t :: Type -> rest :: {Type}
+val foldRX2 : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type) -> ctx :: {Unit}
+ -> (nm :: Name -> t :: K -> rest :: {K}
-> fn [[nm] ~ rest] =>
- tf t -> xml ctx [] [])
- -> r :: {Type} -> $(map tf r) -> xml ctx [] []
-
-val foldT2RX : tf :: ((Type * Type) -> Type) -> ctx :: {Unit}
- -> (nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf t -> xml ctx [] [])
- -> r :: {(Type * Type)} -> $(map tf r) -> xml ctx [] []
-
-val foldT3RX : tf :: ((Type * Type * Type) -> Type) -> ctx :: {Unit}
- -> (nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf t -> xml ctx [] [])
- -> r :: {(Type * Type * Type)} -> $(map tf r) -> xml ctx [] []
-
-val foldTRX2 : tf1 :: (Type -> Type) -> tf2 :: (Type -> Type) -> ctx :: {Unit}
- -> (nm :: Name -> t :: Type -> rest :: {Type}
- -> fn [[nm] ~ rest] =>
- tf1 t -> tf2 t -> xml ctx [] [])
- -> r :: {Type}
- -> $(map tf1 r) -> $(map tf2 r) -> xml ctx [] []
-
-val foldT2RX2 : tf1 :: ((Type * Type) -> Type) -> tf2 :: ((Type * Type) -> Type)
- -> ctx :: {Unit}
- -> (nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf1 t -> tf2 t -> xml ctx [] [])
- -> r :: {(Type * Type)}
- -> $(map tf1 r) -> $(map tf2 r) -> xml ctx [] []
-
-
-val foldT3RX2 : tf1 :: ((Type * Type * Type) -> Type) -> tf2 :: ((Type * Type * Type) -> Type)
- -> ctx :: {Unit}
- -> (nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)}
- -> fn [[nm] ~ rest] =>
- tf1 t -> tf2 t -> xml ctx [] [])
- -> r :: {(Type * Type * Type)}
- -> $(map tf1 r) -> $(map tf2 r) -> xml ctx [] []
+ tf1 t -> tf2 t -> xml ctx [] [])
+ -> r ::: {K} -> folder r
+ -> $(map tf1 r) -> $(map tf2 r) -> xml ctx [] []
val queryX : tables ::: {{Type}} -> exps ::: {Type} -> ctx ::: {Unit}
-> sql_query tables exps