summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ur/basis.urs2
-rw-r--r--lib/ur/listPair.ur16
-rw-r--r--lib/ur/listPair.urs3
-rw-r--r--lib/ur/option.ur5
-rw-r--r--lib/ur/option.urs2
5 files changed, 27 insertions, 1 deletions
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index c893e65d..be13c684 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -1019,6 +1019,8 @@ val checkMime : string -> option mimeType
val returnBlob : t ::: Type -> blob -> mimeType -> transaction t
val blobSize : blob -> int
val textBlob : string -> blob
+val textOfBlob : blob -> option string
+(* Returns [Some] exactly when the blob contains no zero bytes. *)
type postBody
val postType : postBody -> string
diff --git a/lib/ur/listPair.ur b/lib/ur/listPair.ur
index 94b92872..c5e70708 100644
--- a/lib/ur/listPair.ur
+++ b/lib/ur/listPair.ur
@@ -40,7 +40,21 @@ fun mp [a] [b] [c] (f : a -> b -> c) =
case (ls1, ls2) of
([], []) => []
| (x1 :: ls1, x2 :: ls2) => f x1 x2 :: map' ls1 ls2
- | _ => error <xml>ListPair.map2: Unequal list lengths</xml>
+ | _ => error <xml>ListPair.mp: Unequal list lengths</xml>
in
map'
end
+
+fun mapM [m] (_ : monad m) [a] [b] [c] (f : a -> b -> m c) =
+ let
+ fun mapM' ls1 ls2 =
+ case (ls1, ls2) of
+ ([], []) => return []
+ | (x1 :: ls1, x2 :: ls2) =>
+ y <- f x1 x2;
+ ls <- mapM' ls1 ls2;
+ return (y :: ls)
+ | _ => error <xml>ListPair.mapM: Unequal list lengths</xml>
+ in
+ mapM'
+ end
diff --git a/lib/ur/listPair.urs b/lib/ur/listPair.urs
index b473e226..9efff405 100644
--- a/lib/ur/listPair.urs
+++ b/lib/ur/listPair.urs
@@ -8,3 +8,6 @@ val all : a ::: Type -> b ::: Type -> (a -> b -> bool) -> list a -> list b -> bo
val mp : a ::: Type -> b ::: Type -> c ::: Type
-> (a -> b -> c) -> list a -> list b -> list c
+
+val mapM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type -> c ::: Type
+ -> (a -> b -> m c) -> list a -> list b -> m (list c)
diff --git a/lib/ur/option.ur b/lib/ur/option.ur
index baa08466..dd186161 100644
--- a/lib/ur/option.ur
+++ b/lib/ur/option.ur
@@ -59,3 +59,8 @@ fun unsafeGet [a] (o : option a) =
case o of
None => error <xml>Option.unsafeGet: encountered None</xml>
| Some v => v
+
+fun mapM [m] (_ : monad m) [a] [b] (f : a -> m b) (x : t a) : m (t b) =
+ case x of
+ None => return None
+ | Some y => z <- f y; return (Some z)
diff --git a/lib/ur/option.urs b/lib/ur/option.urs
index c30c40e7..705c0313 100644
--- a/lib/ur/option.urs
+++ b/lib/ur/option.urs
@@ -14,3 +14,5 @@ val bind : a ::: Type -> b ::: Type -> (a -> option b) -> t a -> t b
val get : a ::: Type -> a -> option a -> a
val unsafeGet : a ::: Type -> option a -> a
+
+val mapM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type -> (a -> m b) -> t a -> m (t b)