[m-users.] How to user filter_map with a nondet function

Razetime rraghu.11502 at gmail.com
Sun Nov 20 04:28:41 AEDT 2022


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


More information about the users mailing list