summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2010-03-02 10:33:49 -0500
committerGravatar Adam Chlipala <adamc@hcoop.net>2010-03-02 10:33:49 -0500
commit74e835c7db56fb5e716add3bb8fe19534b557282 (patch)
treecdb41c09be72bd53807f60fd2983698b9e244bc3
parent3058e5f4192f8b9617ae157cb5d1e6040d79a8d9 (diff)
Monad.foldMapR
-rw-r--r--lib/ur/monad.ur14
-rw-r--r--lib/ur/monad.urs10
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/ur/monad.ur b/lib/ur/monad.ur
index 689e6b26..211b6cbd 100644
--- a/lib/ur/monad.ur
+++ b/lib/ur/monad.ur
@@ -78,3 +78,17 @@ fun mapR2 [K] [m] (_ : monad m) [tf1 :: K -> Type] [tf2 :: K -> Type] [tr :: K -
v' <- f [nm] [t] v1 v2;
return (acc ++ {nm = v'}))
{}
+
+fun foldMapR [K] [m] (_ : monad m) [tf :: K -> Type] [tf' :: K -> Type] [tr :: {K} -> Type]
+ (f : nm :: Name -> t :: K -> rest :: {K}
+ -> [[nm] ~ rest] =>
+ tf t -> tr rest -> m (tf' t * tr ([nm = t] ++ rest)))
+ (i : tr []) [r ::: {K}] (fl : folder r) =
+ @Top.fold [fn r :: {K} => $(map tf r) -> m ($(map tf' r) * tr r)]
+ (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
+ (acc : _ -> m ($(map tf' rest) * tr rest)) r =>
+ p <- acc (r -- nm);
+ p' <- f [nm] [t] [rest] ! r.nm p.2;
+ return ({nm = p'.1} ++ p.1, p'.2))
+ (fn _ => return ({}, i))
+ fl
diff --git a/lib/ur/monad.urs b/lib/ur/monad.urs
index 05f201e0..cf20dd0f 100644
--- a/lib/ur/monad.urs
+++ b/lib/ur/monad.urs
@@ -50,3 +50,13 @@ val mapR2 : K --> m ::: (Type -> Type) -> monad m
-> tr :: (K -> Type)
-> (nm :: Name -> t :: K -> tf1 t -> tf2 t -> m (tr t))
-> r ::: {K} -> folder r -> $(map tf1 r) -> $(map tf2 r) -> m ($(map tr r))
+
+val foldMapR : K --> m ::: (Type -> Type) -> monad m
+ -> tf :: (K -> Type)
+ -> tf' :: (K -> Type)
+ -> tr :: ({K} -> Type)
+ -> (nm :: Name -> t :: K -> rest :: {K}
+ -> [[nm] ~ rest] =>
+ tf t -> tr rest -> m (tf' t * tr ([nm = t] ++ rest)))
+ -> tr []
+ -> r ::: {K} -> folder r -> $(map tf r) -> m ($(map tf' r) * tr r)