[mercury-users] Another place for existentials?

Ralph Becket rbeck at microsoft.com
Wed Aug 2 01:42:56 AEST 2000


I've been coding up a framework for playing around with CSPs using
typeclasses.  What I wanted was to express the fact that a csp
typeclass had to be related to a node typeclass, so I wrote something
like

:- typeclass csp(CSP, Node) <= node(Node) where [ ... ].

where the node/1 typeclass was quite independent and defined
elsewhere.

I then ran into problems when I wrote a predicate that required
its argument to be a csp/2, but didn't care about the type of the
node it was related to.  My first attempt was:

:- func solve(CSP) = CSP <= csp(CSP, _SomeNode).

The compiler didn't like this because the typeclass constraint
contained variables that didn't appear on the LHS.

My second attempt was

:- func solve(CSP) = CSP <= (csp(CSP, SomeNode), node(SomeNode)).

but this died too, for similar reasons.

My final attempts, before ditching the csp/2 idea in favour of a
somewhat more cumbersome csp/1 + node/1 annotations on methods
approach, looked like this:

:- some [Node] func solve(CSP) = CSP <= csp(CSP, Node).

or even

:- func solve(CSP) = CSP <= (some [Node] csp(CSP, Node)).

They didn't work either.

Am I abusing the typeclass system trying to do this or is there
some scope for use of existentials here?

Ralph

--
Ralph Becket      |      MSR Cambridge      |      rbeck at microsoft.com 
--------------------------------------------------------------------------
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