[m-dev.] for review: allow clauses in instance declarations

David Glen JEFFERY dgj at cs.mu.OZ.AU
Thu Sep 7 14:36:29 AEDT 2000


On 07-Sep-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> 
> Estimated hours taken: 8
> 
> Allow typeclass instance declarations to contain clauses, as an
> alternative to the current `pred(<MethodName>) is <ImplName>)' syntax.
> This avoids the need for the user to explicitly define names for
> procedures that just implement type class methods.

Nice one Fergus. It looks great. I've only got a couple of comments.

> Index: compiler/check_typeclass.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/check_typeclass.m,v
> retrieving revision 1.31
> diff -u -d -r1.31 check_typeclass.m
> --- compiler/check_typeclass.m	2000/07/06 06:25:07	1.31
> +++ compiler/check_typeclass.m	2000/09/06 08:51:49


> +	% list__map_foldl2(Pred, InList, OutList, StartA, EndA, StartB, EndB)
> +	% calls Pred with two accumulator (with the initial values of
> +	% StartA and StartB respectively) on each element of InList
> +	% (working left-to-right) to transform InList into OutList.
> +	% The final values of the accumulators are returned in EndA
> +	% and EndB respectively.
> +:- pred list_map_foldl2(pred(X, Y, Z, Z, W, W), list(X), list(Y), Z, Z, W, W).
> +:- mode list_map_foldl2(pred(in, out, in, out, di, uo) is det,
> +			     in, out, in, out, di, uo) is det.
> +
> +list_map_foldl2(_, [],  [], A, A) -->
> +        [].
> +list_map_foldl2(P, [H0|T0], [H|T], A0, A) -->
> +        call(P, H0, H, A0, A1),
> +        list_map_foldl2(P, T0, T, A1, A).

One for the standard library. I've written this one myself a couple of times...
there are definitely times when it is useful.

> +			Result = ok(instance_method(PredOrFunc,
> +					ClassMethodName,
> +					% XXX FIXME handle multiple clauses
> +					clauses([Item]),
> +					ArityInt, Context))

It would be good if you could fix that XXX before committing. (If it a
major hassle, leave it out for now, but it would be good).


dgj
-- 
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student,                    | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.|     With sufficient formality
The University of Melbourne     |     The sheerist banality
Australia                       | Will be hailed by the critics: "Miraculous!"
                                |     -- Anon.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list