[mercury-users] Typeclass problem (bug, misunderstanding, oth er?)

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Aug 4 00:52:40 AEST 2000


On 03-Aug-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> > From: Fergus Henderson [mailto:fjh at cs.mu.OZ.AU]
> > 
> > > 	:- func solve(CSP, Node) = CSP <= csp(CSP, Node).
> > > 	:- mode solve(in, unused) = out is det.
> > > 
> > > 	...
> > > 	main -->
> > > 		{ node_type(DummyNode) },
> > > 		{ Sol = solve(CSP, DummyNode) },
> > > 		...
> 
> Unfortunately, this still doesn't seem to do the trick.
> I've changed csp/1 to csp/2:
> 
> :- typeclass csp(T, N) <= node(N) where [ ... ].
> 
> and the signature of the search predicate to
> 
> :- pred solve(conflict_fn, bool, N, T, T) <= csp(T, N).
> :- mode solve(in(conflict_fn), out, unused, in, out) is det.
> 
> the source code for solve/5 is the same as before
> 
> solve(CFn, Solved, DummyNode) -->
>     ( if top_exhausted then
>         pop_stack(PoppedNodes),
>         push_agenda(PoppedNodes),

OK, you've passed the DummyNode in; but you haven't done anything with it.
So the type of PoppedNodes is still unconstrained.
You need to add some code to constrain the type of PoppedNodes
so that it uses the same node type as that used for DummyNode,
e.g. a call to

	  { PoppedNodes `has_same_type_as` [DummyNode] }

where `has_same_type_as` is defined as

	:- pred has_same_type_as(T, T).
	:- mode has_same_type_as(unused, unused) is det.
	has_same_type_as(_, _).

>         pop_agenda(CFn, NewTop),
>         push_stack(CFn, NewTop),

Likewise here:

	  { NewTop `has_same_type_as` DummyNode }

-- 
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