[mercury-users] Again: cc_ problem - what is Context requiring all solutions...

Simon Taylor stayl at cs.mu.OZ.AU
Wed Sep 5 05:27:04 AEST 2001


On 04-Sep-2001, Ondrej Bojar <oboj7042 at ss1000.ms.mff.cuni.cz> wrote:
> On Wed, 5 Sep 2001, Simon Taylor wrote:
> > On 04-Sep-2001, Ondrej Bojar <oboj7042 at ss1000.ms.mff.cuni.cz> wrote:
> > > I got this error:
> > >
> > > fstag.m:081: Error: call to predicate `fstag:cc_tagmap/2' with determinism
> > > `cc_nondet'
> > > fstag.m:081:   occurs in a context which requires all solutions.
> > >
> > > And the context is:
>
> :- pred fs2taglist(fs::in, int::in, list(char)::in, list(char)::out) is
> cc_multi.
> 
> fs2taglist(_FS, 0, TagL, TagL).
> fs2taglist(FS, Ind, InTagL, OutTagL) :-
>   (
>     cc_tagmap(Ind, Path),
>     extract(FS, Path, Value),
>     tagmap(Path, Value, Ind, C)
>   ;
>     C = ('-')
>   ),
>   TempTagL = [C|InTagL],
>   fs2taglist(FS, Ind -1, TempTagL, OutTagL).
> 
> :- pred extract(dag::in, attrpath::in, dag::out) is nondet.
> 
> :- pred cc_tagmap(int::in, attrpath::out) is nondet.
>           %                                  ^^^^^^
>           % This is the place, where I want cc_nondet
> cc_tagmap(Ind, Path) :-
>   tagmap(Path, _Value, Ind, _Char).

> > > Why is cc_tagmap in a context requiring all solutions? It's embedded in
> > > my_something which is cc_ as well.

A determinism declaration of cc_nondet on a predicate is a promise
that execution will never need to backtrack into that predicate. In
`fs2taglist', if `extract' fails, execution will need to backtrack
into `cc_tagmap' to try another solution.
 
> % and tagmap is like this:
> 
> :- pred tagmap(attrpath, dag, int, char).
> :- mode tagmap(out, out, in, out).
> % and also other modes
> :- mode tagmap(uo, uo, in, in).
> :- mode tagmap(in, in, in, out).
> 
> tagmap(cat-attrpathend, da(noun), 1, 'N').
> tagmap(cat-attrpathend, da(verb), 1, 'V').
> tagmap(cat-attrpathend, da(symbol), 1, 'Z').
> tagmap(cat-attrpathend, da(adj), 1, 'A').
> tagmap(cat-attrpathend, da(adv), 1, 'D').
> tagmap(cat-attrpathend, da(prep), 1, 'R').
> 
> tagmap(agr-(gend-attrpathend), da(masc), 3, 'M').
> tagmap(agr-(gend-attrpathend), da(fem), 3, 'F').
> tagmap(agr-(gend-attrpathend), da(neut), 3, 'N').
> 
> ...
> The table then goes on, giving for *some* indices and *some* characters
> different paths and dags. But for sure, for any index there is always at
> most one path supplied -- and that is what cc_tagmap should extract.

`cc_tagmap' is actually semidet, but the compiler won't be smart
enough to work out that all of the solutions will be the same.
You can use promise_only_solution (in builtin.m) to tell the
compiler that there are no more solutions after the first.

:- pred cc_tagmap(int::in, attrpath::out) is semidet.

cc_tagmap(Ind, Result) :-
	Result = promise_only_solution(
		(pred(Path::out) is cc_nondet :-
			tagmap(Path, _Value, Ind, _Char)
		)).

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