[m-dev.] for review: tuples [1]

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Sep 15 17:18:45 AEDT 2000


On 14-Aug-2000, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> 
> Fergus wrote:
> > For example, here's how I might implement an instance of `ord' for
> > tuples:
> > 
> >       :- func tuple_compare(T, T, comparison_result) <= tuple(T).
> >       tuple_compare(X, Y, R) :-
> >               tuple_arity(X, N),
> >               tuple_compare_2(X, Y, 0, N).
> > 
> >       tuple_compare_2(X, Y, I, N, R) :-
> >               ( I = N ->
> >                       R = (=)
> >               ;
> >                       XI = tuple_arg(X, I),
> >                       YI = tuple_arg(Y, I),
> >                       compare(XI, YI, R0),
> >                       ( R0 = (=) ->
> >                               tuple_compare_2(X, Y, I + 1, N, R)
> >                       ;
> >                               R = R0
> >                       )
> >               ).
> 
> It's a bit more complicated than this. For the code above,
> the typechecker won't be able to work out that the type of
> XI and YI is an instance of `ord'.

Hmm, good point.

There doesn't seem to be any easy solution.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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