[mercury-users] Existential Types: Passing over typeclass of enclosed types

Jörg Roman Rudnick joerg.rudnick at t-online.de
Mon Apr 30 01:03:11 AEST 2007

Dear all,

in his Ph.D. thesis,

David Jeffery:
    Expressive Type Systems for Logic Programming Languages
    University of Melbourne; February, 2002,

David Jeffery in p. 82 ff. sheds an impression a typeclass of an 
enclosed type may be passed over to its existential type wrapper, i.e.

:-typeclass x_y_point(T) where [
    pred get_x(T::in, float::out) is det,
    pred get_y(T::in, float::out) is det,
    pred set_x(T::in, float::in, T::out) is det,
    pred set_y(T::in, float::in, T::out) is det

:-type x_y_point --->
    some [T] x_y_point(T) => x_y_point(T).

:-instance x_y_point(x_y_point).

:-instance x_y_point(x_y_point) where [
    ( get_x(x_y_point(P), X) :-
            get_x(P, X)
    ( get_y(x_y_point(P), Y) :-
            get_y(P, Y)
    ( set_x(x_y_point(P0), X, 'new x_y_point'(P)) :-
            set_x(P0, X, P)
    ( set_y(x_y_point(P0), Y, 'new x_y_point'(P)) :-
            set_y(P0, Y, P)

In consideration inhowfar to apply existential types, I discovered this 
does not seem so for

    pred add(T::in, T::in, T::out) is det,
    ( add(x_y_point(P1), x_y_point(P2), 'new x_y_point'(P)) :-
            add(P1, P2, P)

with the consequence that one can't use more than a single parameter in 
in-mode - otherwise, a type clash is reported, as the compiler expects 
the exact type instances to be different.

Now my question:


(1) it seems the very common case that such params actually do share the 
same type_desc, and

(2) being able to use several existentially typed in-mode params is most 
useful (or even critical) for application,

is it possible to add an explicit assertion that identical types are used?

Thank you in advance,


mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list