[mercury-users] Cann't understand compiler error
stormie at hotmail.it
stormie at hotmail.it
Thu Sep 6 12:17:14 AEST 2007
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.
%%%%%%%%%% Start of Mercury Code
:- module exp1.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module list,string.
:- type type1 ---> t(string).
:- type type2 ---> c(type1,type1).
main(!IO) :-
io.write_string('Halo!! !! \n', !IO),
X = [t('1'),t('2'),t('3'),t('4')],
Y = [t('a'),t('b'),t('c'),t('d')],
combine(X,Y,Out),
displayt2(Out,!IO).
:- pred displayt1(list(type1)::in,io::di, io::uo) is det.
displayt1([],!IO).
displayt1([X|Xs],!IO):-
displayt1(Xs,!IO),
io.write(X,!IO).
:- pred displayt2(list(type2)::in,io::di, io::uo) is det.
displayt2([],!IO).
displayt2([X|Xs],!IO):-
displayt2(Xs,!IO),
io.write(X,!IO).
:- 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).
%%%%%%%%%%%%%%%%%%%%%%% End of Mercury Code
--
I am able to work out similar logic in prolog,
e.g. with following using constraints
combine( [], [] ,G) :- G = [].
combine( [A|As],[B|Bs], G):-
combine(As,Bs, G1),
append([c(A,B)],G1,G)
applying goal of
?- combine([x,y,z],[1,2,3],G).
G = [c(x, 1), c(y, 2), c(z, 3)] ;
No
_________________________________________________________________
Make shopping exciting. Find what you want @ www.eBay.com.au
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Frover%2Eebay%2Ecom%2Frover%2F1%2F705%2D10129%2D5668%2D323%2F4%2F%3Fid%3D6&_t=763807330&_r=email_taglines_EBAY&_m=EXT
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20070906/5855b65a/attachment.html>
More information about the users
mailing list