comparison lib/ur/monad.ur @ 1093:8d3aa6c7cee0

Make summary unification more conservative; infer implicit arguments after applications
author Adam Chlipala <adamc@hcoop.net>
date Sat, 26 Dec 2009 11:56:40 -0500
parents 37dd42935dad
children ad15700272f6
comparison
equal deleted inserted replaced
1092:6f4b05fc4361 1093:8d3aa6c7cee0
1 fun exec [m ::: Type -> Type] (_ : monad m) [ts ::: {Type}] r (fd : folder ts) = 1 fun exec [m ::: Type -> Type] (_ : monad m) [ts ::: {Type}] r (fd : folder ts) =
2 foldR [m] [fn ts => m $ts] 2 @foldR [m] [fn ts => m $ts]
3 (fn [nm :: Name] [v :: Type] [rest :: {Type}] [[nm] ~ rest] action acc => 3 (fn [nm :: Name] [v :: Type] [rest :: {Type}] [[nm] ~ rest] action acc =>
4 this <- action; 4 this <- action;
5 others <- acc; 5 others <- acc;
6 return ({nm = this} ++ others)) 6 return ({nm = this} ++ others))
7 (return {}) [ts] fd r 7 (return {}) fd r
8 8
9 fun ignore [m ::: Type -> Type] (_ : monad m) [t] (v : m t) = x <- v; return () 9 fun ignore [m ::: Type -> Type] (_ : monad m) [t] (v : m t) = x <- v; return ()
10 10
11 fun mp [m] (_ : monad m) [a] [b] f m = 11 fun mp [m] (_ : monad m) [a] [b] f m =
12 v <- m; 12 v <- m;
14 14
15 fun foldR [K] [m] (_ : monad m) [tf :: K -> Type] [tr :: {K} -> Type] 15 fun foldR [K] [m] (_ : monad m) [tf :: K -> Type] [tr :: {K} -> Type]
16 (f : nm :: Name -> t :: K -> rest :: {K} 16 (f : nm :: Name -> t :: K -> rest :: {K}
17 -> [[nm] ~ rest] => 17 -> [[nm] ~ rest] =>
18 tf t -> tr rest -> m (tr ([nm = t] ++ rest))) 18 tf t -> tr rest -> m (tr ([nm = t] ++ rest)))
19 (i : tr []) [r :: {K}] (fl : folder r) = 19 (i : tr []) [r ::: {K}] (fl : folder r) =
20 Top.fold [fn r :: {K} => $(map tf r) -> m (tr r)] 20 @Top.fold [fn r :: {K} => $(map tf r) -> m (tr r)]
21 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] 21 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
22 (acc : _ -> m (tr rest)) r => 22 (acc : _ -> m (tr rest)) r =>
23 acc' <- acc (r -- nm); 23 acc' <- acc (r -- nm);
24 f [nm] [t] [rest] ! r.nm acc') 24 f [nm] [t] [rest] ! r.nm acc')
25 (fn _ => return i) 25 (fn _ => return i)
26 [_] fl 26 fl
27 27
28 fun foldR2 [K] [m] (_ : monad m) [tf1 :: K -> Type] [tf2 :: K -> Type] [tr :: {K} -> Type] 28 fun foldR2 [K] [m] (_ : monad m) [tf1 :: K -> Type] [tf2 :: K -> Type] [tr :: {K} -> Type]
29 (f : nm :: Name -> t :: K -> rest :: {K} 29 (f : nm :: Name -> t :: K -> rest :: {K}
30 -> [[nm] ~ rest] => 30 -> [[nm] ~ rest] =>
31 tf1 t -> tf2 t -> tr rest -> m (tr ([nm = t] ++ rest))) 31 tf1 t -> tf2 t -> tr rest -> m (tr ([nm = t] ++ rest)))
32 (i : tr []) [r :: {K}] (fl : folder r) = 32 (i : tr []) [r ::: {K}] (fl : folder r) =
33 Top.fold [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> m (tr r)] 33 @Top.fold [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> m (tr r)]
34 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] 34 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
35 (acc : _ -> _ -> m (tr rest)) r1 r2 => 35 (acc : _ -> _ -> m (tr rest)) r1 r2 =>
36 acc' <- acc (r1 -- nm) (r2 -- nm); 36 acc' <- acc (r1 -- nm) (r2 -- nm);
37 f [nm] [t] [rest] ! r1.nm r2.nm acc') 37 f [nm] [t] [rest] ! r1.nm r2.nm acc')
38 (fn _ _ => return i) 38 (fn _ _ => return i)
39 [_] fl 39 fl
40 40
41 fun foldR3 [K] [m] (_ : monad m) [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type] [tr :: {K} -> Type] 41 fun foldR3 [K] [m] (_ : monad m) [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type] [tr :: {K} -> Type]
42 (f : nm :: Name -> t :: K -> rest :: {K} 42 (f : nm :: Name -> t :: K -> rest :: {K}
43 -> [[nm] ~ rest] => 43 -> [[nm] ~ rest] =>
44 tf1 t -> tf2 t -> tf3 t -> tr rest -> m (tr ([nm = t] ++ rest))) 44 tf1 t -> tf2 t -> tf3 t -> tr rest -> m (tr ([nm = t] ++ rest)))
45 (i : tr []) [r :: {K}] (fl : folder r) = 45 (i : tr []) [r ::: {K}] (fl : folder r) =
46 Top.fold [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r) -> m (tr r)] 46 @Top.fold [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r) -> m (tr r)]
47 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] 47 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
48 (acc : _ -> _ -> _ -> m (tr rest)) r1 r2 r3 => 48 (acc : _ -> _ -> _ -> m (tr rest)) r1 r2 r3 =>
49 acc' <- acc (r1 -- nm) (r2 -- nm) (r3 -- nm); 49 acc' <- acc (r1 -- nm) (r2 -- nm) (r3 -- nm);
50 f [nm] [t] [rest] ! r1.nm r2.nm r3.nm acc') 50 f [nm] [t] [rest] ! r1.nm r2.nm r3.nm acc')
51 (fn _ _ _ => return i) 51 (fn _ _ _ => return i)
52 [_] fl 52 fl
53 53
54 fun mapR [K] [m] (_ : monad m) [tf :: K -> Type] [tr :: K -> Type] 54 fun mapR [K] [m] (_ : monad m) [tf :: K -> Type] [tr :: K -> Type]
55 (f : nm :: Name -> t :: K -> tf t -> m (tr t)) = 55 (f : nm :: Name -> t :: K -> tf t -> m (tr t)) =
56 @@foldR [m] _ [tf] [fn r => $(map tr r)] 56 @@foldR [m] _ [tf] [fn r => $(map tr r)]
57 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] (v : tf t) 57 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] (v : tf t)