Re: [m-users.] How to user filter_map with a nondet function
Razetime <[email protected]>
| Newsgroups | gmane.comp.lang.mercury.general |
|---|---|
| Message-ID | <CAMtxHUsmiXz_JqopBFui=mj8kx48=63pdn21gr2xeq__rEdKsQ@mail.gmail.com> |
My main question here is "how do I use a nondet predicate inside a semidet predicate and make it infer as semidet"? changing the mode to nondet and semidet both don't work, which is why i asked. On 11/20/22, Volker Wysk <[email protected]> wrote: > Hi > > When calling a predicate, the modes must match one of the mode lines of the > predicate. Since filter_map has only one mode/mode line, the passed > predicate must match that. This means that the passed predicate must be > semidet, not cc_nondet. > > You might be able to copy the source code of the filter_map predicate, > rename it to, say, filter_map_1 and add a second mode line, with the > determinism category cc_nondet of the higher order argument. > > However, I don't understand what a cc_nondet predicate would do. I've never > seen it be used that way. Of course, you can just try it out. > > Cheers, > Volker > > > Am Samstag, dem 19.11.2022 um 22:58 +0530 schrieb Razetime: >> :- module a10. >> >> :- interface. >> :- import_module io. >> :- pred main(io::di,io::uo) is det. >> >> :- implementation. >> :- import_module alib. >> :- import_module list,string,int,char. >> >> :- pred go(int::out,int::out,cl::in,cl::out) is nondet. >> go(X,Y) --> l("value "),num(X),l(" goes to bot "),num(Y). >> >> :- pred give(int::out,int::out,int::out,cl::in,cl::out) is nondet. >> give(X,Y,Z) --> l("bot "),num(X),l(" gives low to bot "),num(Y),l(" >> and high to "),num(Z). >> >> main(!IO):- >> rlinesc("inp/10",L0,!IO), >> filter_map((pred(X::in,{Y,Z}::out) is cc_nondet:- >> go(Y,Z,X,[]) >> ),L0,As,Mo), >> print_line(As,!IO) >> . >> >> alib is here: https://github.com/razetime/aoc/blob/main/16/alib.m >> >> I'm trying to use the DCG `go` with filter_map to parse lines which >> satisfy the predicate. I get the following error: >> >> Making Mercury/int3s/a10.int3 >> Making Mercury/ints/a10.int >> Making Mercury/cs/a10.c >> For more information, recompile with `-E'. >> a10.m:019: In clause for `main(di, uo)': >> a10.m:019: in argument 1 of call to predicate `list.filter_map'/4: >> a10.m:019: mode error: variable `V_14' has instantiatedness >> a10.m:019: /* unique */ (pred(in, out) is cc_nondet), >> a10.m:019: expected instantiatedness was `(pred(in, out) is semidet)'. >> a10.m:019: In clause for predicate `main'/2: >> a10.m:019: warning: variable `Mo' occurs only once in this scope. >> ** Error making `Mercury/cs/a10.c'. >> >> I do understand that I can change num(X) in alib.m, but I would like >> to know if i can make the determinism check succeed in other ways. >> _______________________________________________ >> users mailing list >> [email protected] >> https://lists.mercurylang.org/listinfo/users > > _______________________________________________ users mailing list [email protected] https://lists.mercurylang.org/listinfo/users