[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 14:29:21 AEDT 2000


On 06-Sep-2000, Thomas Conway <conway at cs.mu.OZ.AU> wrote:
> On Wed, Sep 06, 2000 at 12:47:15PM EST, David Glen JEFFERY wrote:
> > 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...).
> 
> Which would still require duplicate code.

Depends how you set things up.

Something like:

:- typeclass point(T) where [
	func getx(T) = float,
	func gety(T) = float,
	func getz(T) = float,
	func point(float, float, float) = T
].

Would mean that you could re-use the code. eg.

:- func distance_between(T, T) = float <= point(T).
distance_between(P1, P2) = 
        sqrt(sqr(getx(P1) - getx(P2)) + sqr(gety(P1) - gety(P2)) 
		+ sqr(gety(P1) - gety(P2))).

(Of course, you still have to effectively duplicate some code at some point
in the typeclass --- the definitions of getx, gety, getz and point would 
be pretty darn similar for world and object coords).


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