comparison lib/ur/monad.ur @ 905:7a4b026e45dd

Library improvements; proper list [un]urlification; remove server-side ServerCalls; eta reduction in type inference
author Adam Chlipala <adamc@hcoop.net>
date Sun, 09 Aug 2009 16:13:27 -0400
parents d1d0b18afd3d
children 8e540df3294d
comparison
equal deleted inserted replaced
904:6d9538ce94d8 905:7a4b026e45dd
5 others <- acc; 5 others <- acc;
6 return ({nm = this} ++ others)) 6 return ({nm = this} ++ others))
7 (return {}) [ts] fd r 7 (return {}) [ts] 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
11 fun foldR [K] [m] (_ : monad m) [tf :: K -> Type] [tr :: {K} -> Type]
12 (f : nm :: Name -> t :: K -> rest :: {K}
13 -> [[nm] ~ rest] =>
14 tf t -> tr rest -> m (tr ([nm = t] ++ rest)))
15 (i : tr []) [r :: {K}] (fl : folder r) =
16 Top.fold [fn r :: {K} => $(map tf r) -> m (tr r)]
17 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
18 (acc : _ -> m (tr rest)) r =>
19 acc' <- acc (r -- nm);
20 f [nm] [t] [rest] ! r.nm acc')
21 (fn _ => return i)
22 [_] fl
23
24 fun foldR2 [K] [m] (_ : monad m) [tf1 :: K -> Type] [tf2 :: K -> Type] [tr :: {K} -> Type]
25 (f : nm :: Name -> t :: K -> rest :: {K}
26 -> [[nm] ~ rest] =>
27 tf1 t -> tf2 t -> tr rest -> m (tr ([nm = t] ++ rest)))
28 (i : tr []) [r :: {K}] (fl : folder r) =
29 Top.fold [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> m (tr r)]
30 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
31 (acc : _ -> _ -> m (tr rest)) r1 r2 =>
32 acc' <- acc (r1 -- nm) (r2 -- nm);
33 f [nm] [t] [rest] ! r1.nm r2.nm acc')
34 (fn _ _ => return i)
35 [_] fl
36
37 fun mapR [K] [m] (_ : monad m) [tf :: K -> Type] [tr :: K -> Type]
38 (f : nm :: Name -> t :: K -> tf t -> m (tr t)) =
39 @@foldR [m] _ [tf] [fn r => $(map tr r)]
40 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] (v : tf t)
41 (acc : $(map tr rest)) =>
42 v' <- f [nm] [t] v;
43 return (acc ++ {nm = v'}))
44 {}