[mercury-users] [petdr at miscrit.be: Report on the ICFP 2000 prog contest]
Tyson Dowd
trd at cs.mu.OZ.AU
Wed Sep 6 13:24:05 AEDT 2000
On 06-Sep-2000, Thomas Charles 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.
Currently yes.
If you could write inline code in the instance declarations, then the
concrete types could just be wrappers around the real implementation.
Then you just have to supply wrapping and unwrapping.
:- type point ---> point(float, float, float).
:- type worldPoint ---> worldpoint(point).
:- type objectPoint ---> objectpoint(point).
:- func vecProd(point(T), point(T)) = point(T).
:- func dotProd(point(T), point(T)) = float.
:- instance vector(worldPoint) where [
func(vecProd/3) is (func(worldpoint(X), worldpoint(Y)) =
worldpoint(vecProd(X, Y))),
func(dotProd/3) is (func(worldpoint(X), worldpoint(Y)) =
dotProd(X, Y))
].
:- instance vector(objectPoint) where [
func(vecProd/3) is (func(objectpoint(X), objectpoint(Y)) =
objectpoint(vecProd(X, Y))),
func(dotProd/3) is (func(objectpoint(X), objectpoint(Y)) =
dotProd(X, Y))
]
And since you are using no-tag types, wrapping and unwrapping are
no-ops.
We don't currently support this syntax -- instead you have to write 4
new functions. But I don't think it would be too hard to accept a pred
expression or func expression after the "is" in an instance declaration.
I'm thinking this would make a pretty good summer student project.
--
Tyson Dowd #
# Surreal humour isn't everyone's cup of fur.
trd at cs.mu.oz.au #
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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