[mercury-users] [petdr at miscrit.be: Report on the ICFP 2000 prog contest]
Thomas Conway
conway at cs.mu.OZ.AU
Wed Sep 6 12:08:54 AEDT 2000
On Wed, Sep 06, 2000 at 11:46:26AM EST, David Overton wrote:
> On Wed, Sep 06, 2000 at 10:57:17AM +1100, schachte at cs.mu.OZ.AU wrote:
> > > It is instructive to note that one of the bugs that took the longest to
> > > find was in the following code:
> > >
> > > inside_sphere(Point, Trans) :-
> > > Point = point_to_object_space(Trans, Point),
> > > mag2(Point) =< 1.0.
> >
> > That's an interesting bug; it's such an easy mistake to make, and so
> > hard to see. The interesting thing about it is that the code doesn't
> > say what you intended, but you *could* have intended what you wrote, so
> > the language really can't find it for you.
>
> One way this bug could have been avoided would be by using different
> types for the object space points and world space points.
Note that I did something like this with terms changing them from:
:- type term
---> variable(var)
; functor(atom, list(term), context)
.
to
:- type term(T)
---> variable(var(T))
; functor(atom, list(term(T)), context)
.
and
:- type var. % abstractly == int.
to
:- type var(T). % abstractly ---> var(int).
That way we made type variables and program variables have different
types in the compiler so that we would get errors when they got mixed.
Of course, I didn't find any errors when I introduced the change because
DJ (dgj) had already sweated over the code long enough to find the
several that were there.
We could easily have made point be:
:- type point(T)
---> point(float, float, float).
:- type worldPointType ---> worldPointType.
:- type objectPointType ---> objectPointType.
:- type worldPoint == point(worldPointType).
:- type objectPoint == point(objectPointType).
This technique of using "place holder" type parameters to distinguish
objects whose type is the "same" is very useful and I've used it lots
of times.
--
Thomas Conway Unicode for terrorists: U+0001 300C
<conway at cs.mu.oz.au> "Tie his hands behind his back"
Mercurian )O+
--------------------------------------------------------------------------
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