[mercury-users] Higher-order unification question

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Tue Feb 27 09:01:27 AEDT 2007

Hi, I receive an error when I pass in an applied higher order term.
What am I doing wrong?

The goal's type:

:- pred svunfold(counter, pred(T, T, SV, SV), T, T, SV, SV).
:- mode svunfold(in, pred(in, out, in, out) is det, in, out, in, out)
        is det.

The argument def:

	  Rnds = (pred(P::(pred(in, in, out) is det), A::in, B::out,
		       RNG0::in, RNG::out) is det :-
	          P(X, RNG0, RNG),
		  B = [X|A]),

the call:

	  svunfold(counter(10), Rnds(random_int), [], Ans, J0, _),

(where random_int/3 is from Julian's typeclassed RNG protocol).

The exact compile error message:

test_series.m:026: In clause for predicate `main'/2:
test_series.m:026:   in argument 2 of call to predicate `svunfold'/6:
test_series.m:026:   in unification of argument
test_series.m:026:   and term `Rnds(V_55)':
test_series.m:026:   type error in argument(s) of higher-order term (with arity
test_series.m:026:   1).
test_series.m:026:   Functor (Rnds) has type `pred(pred(T, V_7, V_6),
test_series.m:026:   (list.list(T)), (list.list(T)), V_7, V_6)',
test_series.m:026:   expected type was `((func V_10) = V_11)'.
** Error making `Mercury/cs/test_series.c'.
make: *** [test_series] Error 1

Why is it looking for (func T0) = T1 as the type? It should be looking for
the type (pred(T0::in, T0::out, T1::in, T1::out).  Just to check, the following
compiles and runs just fine:

	  Ints = (pred(A::in, B::out, RNG0::in, RNG::out) is det :-
	          random_int(X, RNG0, RNG),
		  B = [X|A]),
	  svunfold(counter(10), Ints, [], Ans, J0, _),

so how do I abstract out the random_<foo> call correctly?

Thanks for the help.

Doug Auclair

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