[mercury-users] Typeclass problem (bug, misunderstanding, oth er?)
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Aug 3 16:16:01 AEST 2000
On 02-Aug-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> In your reply to my other typeclass help request, you suggest adding
> a dummy parameter to the function in question:
>
> :- func solve(CSP, Node) = CSP <= csp(CSP, Node).
> :- mode solve(in, unused) = out is det.
>
> ...
> main -->
> { node_type(DummyNode) },
> { Sol = solve(CSP, DummyNode) },
> ...
>
> % this predicate just constrains the type of its
> % argument to be `int'
> :- pred node_type(my_node::unused) is det.
BTW, `int' there is a typo -- to make the comment match the
code, it should be `my_node'. Sorry 'bout that.
> node_type(_).
>
> While this will work, it does seem to be something of a hack. I
> wonder if there's some small addition we could make to the language
> that would handle this more gracefully?
One thing that would certainly help is syntax for explicit type
qualification. Then you could write it as
main -->
{ Sol = solve(CSP, _::my_node) },
...
without needing to define the `node_type' predicate.
This one has been on the list for a while, and will
probably actually happen sometime soon.
> E.g.
>
> :- func solve(CSP) = CSP <= (some [Node] csp(CSP, Node)).
>
> solve(CSP0) = CSP :-
> some [PoppedNodes, TopNode] (
> ... code in which it would otherwise be
> ... impossible to work out a type for
> ... PoppedNodes and TopNode, but which
> ... doesn't need to know
> ).
That won't work in general, since the choice of the node type
could affect the semantics.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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