[mercury-users] Cann't understand compiler error

Peter Wang novalazy at gmail.com
Thu Sep 6 12:58:27 AEST 2007

On 2007-09-06, stormie at hotmail.it <stormie at hotmail.it> wrote:
> Can anyone help me to explain the compilation errors?
> I am trying to combine elements two lists of type1 to get a list of type2.
> Thanks in advance...
> -
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> stormie at stormie-laptop:~/logic/dvl_mercury/testmod$ mmc  --make exp1
> Making Mercury/int3s/exp1.int3
> Making Mercury/ints/exp1.int
> Making Mercury/cs/exp1.c
> exp1.m:040: In `combine'(in, in, out):
> exp1.m:040:   error: determinism declaration not satisfied.
> exp1.m:040:   Declared `det', inferred `semidet'.
> exp1.m:041:   In argument 2 of clause head:
> exp1.m:041:   unification of `HeadVar__2' and `list.[]' can fail.
> exp1.m:042:   In argument 2 of clause head:
> exp1.m:042:   unification of `HeadVar__2' and `list.[B | Bs]' can fail.
> :- pred combine( list(type1)::in, list(type1)::in, list(type2)::out) is det..
> combine( [], [] ,G) :- G = [].
> combine( [A|As],[B|Bs], G):-
>     combine(As, Bs, G1),
>     append([c(A,B)],G1,G).

The compiler is telling you that combine does not cover the
possibilities that the lists could have mismatching lengths.  Since
combine is declared to be `det', it cannot silently fail for those cases.

The solution is either to declare combine as semidet or account for the
unexpected cases and abort if they are encountered at runtime:

    combine([], [_ | _], _) :-
	error("combine: mismatched lists").
    combine([_ | _], [], _) :-
	error("combine: mismatched lists").


P.S. the syntax for strings is double quotes.

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