[mercury-users] [petdr at miscrit.be: Report on the ICFP 2000 prog contest]
David Glen JEFFERY
dgj at students.cs.mu.oz.au
Wed Sep 6 12:47:15 AEDT 2000
On 06-Sep-2000, schachte at cs.mu.OZ.AU <schachte at cs.mu.OZ.AU> wrote:
>
> Wouldn't it be easier to just do:
>
> :- type worldPoint ---> worldpoint(float,float,float).
> :- type objectPoint ---> objectpoint(float,float,float).
>
> What advantage do you get from the more complicated (and, IMHO, less
> intuitive) approach?
The advantage is that you can still write code which manipulates a point(T),
and have it work for points in world and object coordinates.
For example, you could quite happily do:
:- func distance_between(point(T), point(T)) = float.
distance_between(point(X1, Y1, Z1), point(X2, Y2, Z2)) =
sqrt(sqr(X1 - X2) + sqr(Y1 - Y2) + sqr(Z1 - Z2)).
This code will work regardless of whether the points are in world or
object space.
If worldPoint and objectPoint were different concrete types (as you've
described above) you would have to duplicate the code (or create
a type class...).
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-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list