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

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


I have a file with a couple of typeclasses (most of
this is chaff, you probably want to focus on the
methods which mention node(N) as a constraint):

:- typeclass csp(T) where [

    pred current_assignments(assgts, T, T),
    mode current_assignments(out, in, out) is det,

    pred top_exhausted(T, T),
    mode top_exhausted(in, out) is semidet,

    pred set_next_top_value(conflict_fn, T, T),
    mode set_next_top_value(in(conflict_fn), in, out) is det,

    pred stack_exhausted(T, T),
    mode stack_exhausted(in, out) is semidet,

    pred push_stack(conflict_fn, N, T, T) <= node(N),
    mode push_stack(in(conflict_fn), in, in, out) is det,

    pred pop_stack(list(N), T, T) <= node(N),
    mode pop_stack(out, in, out) is det,

    pred agenda_exhausted(T, T),
    mode agenda_exhausted(in, out) is semidet,

    pred push_agenda(list(N), T, T) <= node(N),
    mode push_agenda(in, in, out) is det,

    pred pop_agenda(conflict_fn, N, T, T) <= node(N),
    mode pop_agenda(in(conflict_fn), out, in, out) is det

].

:- typeclass node(N) where [

    func var(N) = var,

    pred exhausted(N),
    mode exhausted(in) is semidet,

    func possible_values(N) = list(value),

    func current_assignment(N) = assgt,

    func reject_current_assignment(N, list(var)) = N,

    func discard_current_assignment(N) = N,

    func reset(N) = N,

    func conflict_set(N) = list(var)
].

var and value are just type synonyms for int, in this 
case, and an assgt is just a var-value pair.  

Then I have a predicate:

:- pred solve(conflict_fn, bool, T, T) <= csp(T).
:- mode solve(in(conflict_fn), out, in, out) is det.

solve(CFn, Solved) -->
    ( if top_exhausted then
        pop_stack(PoppedNodes),
        push_agenda(PoppedNodes),
        ( if stack_exhausted then
            { Solved = no }
          else
            set_next_top_value(CFn),
            solve(CFn, Solved)
        )
      else if agenda_exhausted then
        { Solved = yes }
      else
        pop_agenda(CFn, NewTop),
        push_stack(CFn, NewTop),
        solve(CFn, Solved)
    ).

where conflict_fn is defined elsewhere and has nothing
to do with nodes or csps.

I get the following error from the compiler (rotd 06 27,
if memory serves):

csp.m:241: In predicate `csp:solve/4':
csp.m:241:   type error: unsatisfied typeclass constraint(s):
csp.m:241:   csp:node(N), csp:node(N).
csp.m:241: In predicate `csp:solve/4':
csp.m:241:   warning: unresolved polymorphism.
csp.m:241:   The variables with unbound types were:
csp.m:241:       NewTop :: N
csp.m:241:       PoppedNodes :: (list:list(N))
csp.m:241:   The unbound type variable(s) will be implicitly
csp.m:241:   bound to the builtin type `void'.
For more information, try recompiling with `-E'.

What does this mean?  I've stared and stared at the definition
of the csp typeclass and I can't for the life of me work out
where the error is.  If anybody can help, I'd be extremely
grateful.

Cheers,

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