From 0dfc87c68d5aba5adac079cb62ae504d82b303b9 Mon Sep 17 00:00:00 2001 From: Arnaud Spiwack Date: Thu, 27 Feb 2014 14:50:40 +0100 Subject: Tacinterp: refactoring using Monad. Adds a combinator List.map_right which chains effects from right to left.--- lib/monad.ml | 24 +++++++++++++++++++++++- lib/monad.mli | 6 ++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/monad.ml b/lib/monad.ml index 773f952def..a1508ae01c 100644 --- a/lib/monad.ml +++ b/lib/monad.ml @@ -32,9 +32,14 @@ module type S = sig (** List combinators *) module List : sig - (** [map f l] applies the monadic effect left to right. *) + (** [map f l] maps [f] on the elements of [l] in left to right + order. *) val map : ('a -> 'b t) -> 'a list -> 'b list t + (** [map f l] maps [f] on the elements of [l] in right to left + order. *) + val map_right : ('a -> 'b t) -> 'a list -> 'b list t + end end @@ -53,6 +58,23 @@ module Make (M:Def) : S with type +'a t = 'a M.t = struct map f l >>= fun l' -> return (a'::l') + let rec map_right f = function + | [] -> return [] + | a::l -> + map f l >>= fun l' -> + f a >>= fun a' -> + return (a'::l') + end end + + + + + + + + + + diff --git a/lib/monad.mli b/lib/monad.mli index 1f04cf5e0c..5c4f74e51d 100644 --- a/lib/monad.mli +++ b/lib/monad.mli @@ -32,8 +32,14 @@ module type S = sig (** List combinators *) module List : sig + (** [map f l] maps [f] on the elements of [l] in left to right + order. *) val map : ('a -> 'b t) -> 'a list -> 'b list t + (** [map f l] maps [f] on the elements of [l] in right to left + order. *) + val map_right : ('a -> 'b t) -> 'a list -> 'b list t + end end -- cgit v1.2.3