comparison lib/ur/top.ur @ 621:8998114760c1

"Hello world" compiles, after replacing type-level fold with map
author Adam Chlipala <adamc@hcoop.net>
date Sat, 21 Feb 2009 15:33:20 -0500
parents 1d34d916c206
children 588b9d16b00a
comparison
equal deleted inserted replaced
620:d828b143e147 621:8998114760c1
6 con sndTT (t :: (Type * Type)) = t.2 6 con sndTT (t :: (Type * Type)) = t.2
7 con fstTTT (t :: (Type * Type * Type)) = t.1 7 con fstTTT (t :: (Type * Type * Type)) = t.1
8 con sndTTT (t :: (Type * Type * Type)) = t.2 8 con sndTTT (t :: (Type * Type * Type)) = t.2
9 con thdTTT (t :: (Type * Type * Type)) = t.3 9 con thdTTT (t :: (Type * Type * Type)) = t.3
10 10
11 con mapTT (f :: Type -> Type) = fold (fn nm t acc [[nm] ~ acc] => 11 con mapUT = fn f :: Type => map (fn _ :: Unit => f)
12 [nm = f t] ++ acc) []
13
14 con mapUT = fn f :: Type => fold (fn nm t acc [[nm] ~ acc] =>
15 [nm = f] ++ acc) []
16
17 con mapT2T (f :: (Type * Type) -> Type) = fold (fn nm t acc [[nm] ~ acc] =>
18 [nm = f t] ++ acc) []
19
20 con mapT3T (f :: (Type * Type * Type) -> Type) = fold (fn nm t acc [[nm] ~ acc] =>
21 [nm = f t] ++ acc) []
22 12
23 con ex = fn tf :: (Type -> Type) => 13 con ex = fn tf :: (Type -> Type) =>
24 res ::: Type -> (choice :: Type -> tf choice -> res) -> res 14 res ::: Type -> (choice :: Type -> tf choice -> res) -> res
25 15
26 fun ex (tf :: (Type -> Type)) (choice :: Type) (body : tf choice) : ex tf = 16 fun ex (tf :: (Type -> Type)) (choice :: Type) (body : tf choice) : ex tf =
67 fun foldTR (tf :: Type -> Type) (tr :: {Type} -> Type) 57 fun foldTR (tf :: Type -> Type) (tr :: {Type} -> Type)
68 (f : nm :: Name -> t :: Type -> rest :: {Type} 58 (f : nm :: Name -> t :: Type -> rest :: {Type}
69 -> fn [[nm] ~ rest] => 59 -> fn [[nm] ~ rest] =>
70 tf t -> tr rest -> tr ([nm = t] ++ rest)) 60 tf t -> tr rest -> tr ([nm = t] ++ rest))
71 (i : tr []) = 61 (i : tr []) =
72 fold [fn r :: {Type} => $(mapTT tf r) -> tr r] 62 fold [fn r :: {Type} => $(map tf r) -> tr r]
73 (fn (nm :: Name) (t :: Type) (rest :: {Type}) (acc : _ -> tr rest) 63 (fn (nm :: Name) (t :: Type) (rest :: {Type}) (acc : _ -> tr rest)
74 [[nm] ~ rest] r => 64 [[nm] ~ rest] r =>
75 f [nm] [t] [rest] r.nm (acc (r -- nm))) 65 f [nm] [t] [rest] r.nm (acc (r -- nm)))
76 (fn _ => i) 66 (fn _ => i)
77 67
78 fun foldT2R (tf :: (Type * Type) -> Type) (tr :: {(Type * Type)} -> Type) 68 fun foldT2R (tf :: (Type * Type) -> Type) (tr :: {(Type * Type)} -> Type)
79 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)} 69 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
80 -> fn [[nm] ~ rest] => 70 -> fn [[nm] ~ rest] =>
81 tf t -> tr rest -> tr ([nm = t] ++ rest)) 71 tf t -> tr rest -> tr ([nm = t] ++ rest))
82 (i : tr []) = 72 (i : tr []) =
83 fold [fn r :: {(Type * Type)} => $(mapT2T tf r) -> tr r] 73 fold [fn r :: {(Type * Type)} => $(map tf r) -> tr r]
84 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) 74 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
85 (acc : _ -> tr rest) [[nm] ~ rest] r => 75 (acc : _ -> tr rest) [[nm] ~ rest] r =>
86 f [nm] [t] [rest] r.nm (acc (r -- nm))) 76 f [nm] [t] [rest] r.nm (acc (r -- nm)))
87 (fn _ => i) 77 (fn _ => i)
88 78
89 fun foldT3R (tf :: (Type * Type * Type) -> Type) (tr :: {(Type * Type * Type)} -> Type) 79 fun foldT3R (tf :: (Type * Type * Type) -> Type) (tr :: {(Type * Type * Type)} -> Type)
90 (f : nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)} 80 (f : nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)}
91 -> fn [[nm] ~ rest] => 81 -> fn [[nm] ~ rest] =>
92 tf t -> tr rest -> tr ([nm = t] ++ rest)) 82 tf t -> tr rest -> tr ([nm = t] ++ rest))
93 (i : tr []) = 83 (i : tr []) =
94 fold [fn r :: {(Type * Type * Type)} => $(mapT3T tf r) -> tr r] 84 fold [fn r :: {(Type * Type * Type)} => $(map tf r) -> tr r]
95 (fn (nm :: Name) (t :: (Type * Type * Type)) (rest :: {(Type * Type * Type)}) 85 (fn (nm :: Name) (t :: (Type * Type * Type)) (rest :: {(Type * Type * Type)})
96 (acc : _ -> tr rest) [[nm] ~ rest] r => 86 (acc : _ -> tr rest) [[nm] ~ rest] r =>
97 f [nm] [t] [rest] r.nm (acc (r -- nm))) 87 f [nm] [t] [rest] r.nm (acc (r -- nm)))
98 (fn _ => i) 88 (fn _ => i)
99 89
100 fun foldTR2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (tr :: {Type} -> Type) 90 fun foldTR2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (tr :: {Type} -> Type)
101 (f : nm :: Name -> t :: Type -> rest :: {Type} 91 (f : nm :: Name -> t :: Type -> rest :: {Type}
102 -> fn [[nm] ~ rest] => 92 -> fn [[nm] ~ rest] =>
103 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest)) 93 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
104 (i : tr []) = 94 (i : tr []) =
105 fold [fn r :: {Type} => $(mapTT tf1 r) -> $(mapTT tf2 r) -> tr r] 95 fold [fn r :: {Type} => $(map tf1 r) -> $(map tf2 r) -> tr r]
106 (fn (nm :: Name) (t :: Type) (rest :: {Type}) 96 (fn (nm :: Name) (t :: Type) (rest :: {Type})
107 (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 => 97 (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 =>
108 f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm))) 98 f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
109 (fn _ _ => i) 99 (fn _ _ => i)
110 100
112 (tr :: {(Type * Type)} -> Type) 102 (tr :: {(Type * Type)} -> Type)
113 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)} 103 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
114 -> fn [[nm] ~ rest] => 104 -> fn [[nm] ~ rest] =>
115 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest)) 105 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
116 (i : tr []) = 106 (i : tr []) =
117 fold [fn r :: {(Type * Type)} => $(mapT2T tf1 r) -> $(mapT2T tf2 r) -> tr r] 107 fold [fn r :: {(Type * Type)} => $(map tf1 r) -> $(map tf2 r) -> tr r]
118 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) 108 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
119 (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 => 109 (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 =>
120 f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm))) 110 f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
121 (fn _ _ => i) 111 (fn _ _ => i)
122 112
124 (tr :: {(Type * Type * Type)} -> Type) 114 (tr :: {(Type * Type * Type)} -> Type)
125 (f : nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)} 115 (f : nm :: Name -> t :: (Type * Type * Type) -> rest :: {(Type * Type * Type)}
126 -> fn [[nm] ~ rest] => 116 -> fn [[nm] ~ rest] =>
127 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest)) 117 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
128 (i : tr []) = 118 (i : tr []) =
129 fold [fn r :: {(Type * Type * Type)} => $(mapT3T tf1 r) -> $(mapT3T tf2 r) -> tr r] 119 fold [fn r :: {(Type * Type * Type)} => $(map tf1 r) -> $(map tf2 r) -> tr r]
130 (fn (nm :: Name) (t :: (Type * Type * Type)) (rest :: {(Type * Type * Type)}) 120 (fn (nm :: Name) (t :: (Type * Type * Type)) (rest :: {(Type * Type * Type)})
131 (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 => 121 (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 =>
132 f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm))) 122 f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
133 (fn _ _ => i) 123 (fn _ _ => i)
134 124
193 <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>) 183 <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>)
194 <xml/> 184 <xml/>
195 185
196 fun queryX (tables ::: {{Type}}) (exps ::: {Type}) (ctx ::: {Unit}) 186 fun queryX (tables ::: {{Type}}) (exps ::: {Type}) (ctx ::: {Unit})
197 (q : sql_query tables exps) [tables ~ exps] 187 (q : sql_query tables exps) [tables ~ exps]
198 (f : $(exps ++ fold (fn nm (fields :: {Type}) acc [[nm] ~ acc] => 188 (f : $(exps ++ map (fn fields :: {Type} => $fields) tables)
199 [nm = $fields] ++ acc) [] tables)
200 -> xml ctx [] []) = 189 -> xml ctx [] []) =
201 query q 190 query q
202 (fn fs acc => return <xml>{acc}{f fs}</xml>) 191 (fn fs acc => return <xml>{acc}{f fs}</xml>)
203 <xml/> 192 <xml/>
204 193
205 fun queryX' (tables ::: {{Type}}) (exps ::: {Type}) (ctx ::: {Unit}) 194 fun queryX' (tables ::: {{Type}}) (exps ::: {Type}) (ctx ::: {Unit})
206 (q : sql_query tables exps) [tables ~ exps] 195 (q : sql_query tables exps) [tables ~ exps]
207 (f : $(exps ++ fold (fn nm (fields :: {Type}) acc [[nm] ~ acc] => 196 (f : $(exps ++ map (fn fields :: {Type} => $fields) tables)
208 [nm = $fields] ++ acc) [] tables)
209 -> transaction (xml ctx [] [])) = 197 -> transaction (xml ctx [] [])) =
210 query q 198 query q
211 (fn fs acc => 199 (fn fs acc =>
212 r <- f fs; 200 r <- f fs;
213 return <xml>{acc}{r}</xml>) 201 return <xml>{acc}{r}</xml>)