[m-rev.] for review: Move some code from std_util.m to maybe.m

Julien Fischer jfischer at opturion.com
Fri Sep 2 10:00:32 AEST 2016


Hi Paul,

On Wed, 31 Aug 2016, Paul Bone wrote:

> Move some code from std_util.m to maybe.m
>
> Deprecate the maybe_pred and maybe_func code in std_lib.m and add a
> predicate version of pred_to_maybe and a new function func_to_maybe to
> maybe.m.
>
> library/std_util.m:
> library/maybe.m:
>    As above.
>
> NEWS:
>    Update news file.

...

> diff --git a/library/maybe.m b/library/maybe.m
> index 89a5da1..2351d8e 100644
> --- a/library/maybe.m
> +++ b/library/maybe.m
> @@ -2,6 +2,7 @@
> % vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
> %---------------------------------------------------------------------------%
> % Copyright (C) 1994-2006, 2010-2011 The University of Melbourne.
> +% Copyright (C) 2016 The Mercury Team.
> % This file may only be copied under the terms of the GNU Library General
> % Public License - see the file COPYING.LIB in the Mercury distribution.
> %---------------------------------------------------------------------------%
> @@ -173,9 +174,15 @@
>     %
>     % Make a maybe value from a semidet predicate.
>     %
> -:- func pred_to_maybe(pred(X)) = maybe(X).
> +:- func pred_to_maybe(pred(T)) = maybe(T).
> :- mode pred_to_maybe(pred(out) is semidet) = out is det.
> 
> +:- pred pred_to_maybe(pred(T), maybe(T)).
> +:- mode pred_to_maybe(pred(out) is semidet, out) is det.

Do we really require a predicate verison of this as well?

> +:- func func_to_maybe((func) = T) = maybe(T).
> +:- mode func_to_maybe((func) = out is semidet) = out is det.
> +
>     % Return the value from within the maybe or a default value if there is
>     % none.
>     %
> @@ -218,12 +225,18 @@ map_fold3_maybe(P, yes(T0), yes(T), !A, !B, !C) :-
> maybe_is_yes(yes(X), X).
> 
> pred_to_maybe(Pred) = Result :-
> +    pred_to_maybe(Pred, Result).
> +
> +pred_to_maybe(Pred, Result) :-
>     ( if Pred(X) then
>         Result = yes(X)
>     else
>         Result = no
>     ).
> 
> +func_to_maybe(PF) =
> +    ( if Y = apply(PF) then yes(Y) else no ).
> +
> maybe_default(_, yes(X)) = X.
> maybe_default(D, no) = D.
> 
> diff --git a/library/std_util.m b/library/std_util.m
> index 39b3854..9b55de3 100644
> --- a/library/std_util.m
> +++ b/library/std_util.m
> @@ -2,6 +2,7 @@
> % vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
> %---------------------------------------------------------------------------%
> % Copyright (C) 1994-2006, 2008 The University of Melbourne.
> +% Copyright (C) 2016 The Mercury Team.
> % This file may only be copied under the terms of the GNU Library General
> % Public License - see the file COPYING.LIB in the Mercury distribution.
> %---------------------------------------------------------------------------%
> @@ -53,9 +54,13 @@
>     % X succeeds, Y is bound to `yes(Z)' where Z is the output of the
>     % call, or to `no' if the call fails.
>     %
> +    % use maybe.pred_to_maybe instead

Capital letter at the start of that sentence, full stop at the end etc.

> +:- pragma obsolete(maybe_pred/3).
> :- pred maybe_pred(pred(T1, T2), T1, maybe(T2)).
> :- mode maybe_pred(pred(in, out) is semidet, in, out) is det.
> 
> +    % use maybe.func_to_maybe instead

Ditto.

Looks fine otherwise.

Julien.


More information about the reviews mailing list