[m-rev.] diff: library improvements for g12

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Dec 13 15:38:05 AEDT 2010


On Mon, 13 Dec 2010, Zoltan Somogyi wrote:

> library/Mmakefile:
> 	Make a module list easier to modify.
>
> library/array.m:
> library/int.m:
> 	Add predicates needed by g12.
>
> NEWS:
> 	Mention the new predicates.
>
> 	Remove announcements of new modes for predicates which are themselves
> 	new.

...

> Index: library/array.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/library/array.m,v
> retrieving revision 1.178
> diff -u -b -r1.178 array.m
> --- library/array.m	18 Nov 2010 04:12:11 -0000	1.178
> +++ library/array.m	9 Dec 2010 06:19:11 -0000

...

> +    % array.map_foldl(P, A, B, !Acc):
> +    % Invoke P(Aelt, Belt, !Acc) on each element of the A array,
> +    % and construct array B from the resulting values of Belt.
> +    %
> +:- pred map_foldl(pred(T1, T2, T3, T3), array(T1), array(T2), T3, T3).
> +:- mode map_foldl(in(pred(in, out, in, out) is det),
> +    in, array_uo, in, out) is det.
> +:- mode map_foldl(in(pred(in, out, in, out) is semidet),
> +    in, array_uo, in, out) is semidet.


I suggest adding (mdi, muo) and (di, uo) accumulators as well.

> +
> +    % array.map_corresponding_foldl(P, A, B, C, !Acc):
> +    %
> +    % Given two arrays A and B, invoke P(Aelt, Belt, Celt, !Acc) on
> +    % each corresponding pair of elements Aelt and Belt. Build up the array C
> +    % from the result Celt values. Return C and the final value of the
> +    % accumulator.
> +    %
> +    % C will have as many elements as A does. In most uses, B will also have
> +    % this many elements, but may have more; it may NOT have fewer.
> +    %
> +:- pred array.map_corresponding_foldl(pred(T1, T2, T3, T4, T4),
> +    array(T1), array(T2), array(T3), T4, T4).
> +:- mode array.map_corresponding_foldl(
> +    in(pred(in, in, out, in, out) is det),
> +    in, in, array_uo, in, out) is det.
> +:- mode array.map_corresponding_foldl(
> +    in(pred(in, in, out, in, out) is semidet),
> +    in, in, array_uo, in, out) is semidet.


Likewise, here.

...

> %-----------------------------------------------------------------------------%
>
> -array.foldr2(P, A, !Acc1, !Acc2) :-
> -    do_foldr2(P, array.min(A), array.max(A), A, !Acc1, !Acc2).
> +foldr2(P, A, !Acc1, !Acc2) :-
> +    do_foldr_2(P, array.min(A), array.max(A), A, !Acc1, !Acc2).
>
> -:- pred do_foldr2(pred(T1, T2, T2, T3, T3), int, int, array(T1), T2, T2,
> +:- pred do_foldr_2(pred(T1, T2, T2, T3, T3), int, int, array(T1), T2, T2,
>     T3, T3).
> -:- mode do_foldr2(pred(in, in, out, in, out) is det, in, in, in, in, out,
> +:- mode do_foldr_2(pred(in, in, out, in, out) is det, in, in, in, in, out,
>     in, out) is det.
> -:- mode do_foldr2(pred(in, in, out, mdi, muo) is det, in, in, in, in, out,
> +:- mode do_foldr_2(pred(in, in, out, mdi, muo) is det, in, in, in, in, out,
>     mdi, muo) is det.
> -:- mode do_foldr2(pred(in, in, out, di, uo) is det, in, in, in, in, out,
> +:- mode do_foldr_2(pred(in, in, out, di, uo) is det, in, in, in, in, out,
>     di, uo) is det.
> -:- mode do_foldr2(pred(in, in, out, in, out) is semidet, in, in, in, in, out,
> +:- mode do_foldr_2(pred(in, in, out, in, out) is semidet, in, in, in, in, out,
>     in, out) is semidet.
> -:- mode do_foldr2(pred(in, in, out, mdi, muo) is semidet, in, in, in, in, out,
> +:- mode do_foldr_2(pred(in, in, out, mdi, muo) is semidet, in, in, in, in, out,
>     mdi, muo) is semidet.
> -:- mode do_foldr2(pred(in, in, out, di, uo) is semidet, in, in, in, in, out,
> +:- mode do_foldr_2(pred(in, in, out, di, uo) is semidet, in, in, in, in, out,
>     di, uo) is semidet.
>
> -do_foldr2(P, Min, I, A, !Acc1, !Acc2) :-
> +do_foldr_2(P, Min, I, A, !Acc1, !Acc2) :-
>     ( I < Min ->
>         true
>     ;
>         P(A ^ unsafe_elem(I), !Acc1, !Acc2),
> -        do_foldr2(P, Min, I - 1, A, !Acc1, !Acc2)
> +        do_foldr_2(P, Min, I - 1, A, !Acc1, !Acc2)
> +    ).


Why have you added the underscore to the do_foldr2?  To me that suggests
it is an auxiliary predicate related to the implementation of foldr, not
foldr2.  Also, the naming of the auxiliary predicate used in the
implementation of foldl2 follows the same scheme - they should at least
be consistent.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list