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

Volker Wysk <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
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
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE6QXGh82Ov3+2nrxp+K4ydFOsHoUFAmN5ODAACgkQ+K4ydFOs
HoVIBQ/+L5vz4R1Z8sZZib+4Isjbv5BY555cK8Zusz86jaWhao1MVBmSNpJV+kKj
VZ5o8MykKA7T/VolW7n2zt4UfGJD4Fg7MCPQ/kTGPVMRYkgRtx1uLTDsVMIbIoAy
IM0Zoebod9B02HbYU1Tsr5ontCchCdQdYzcV0lpw47BsOuByMDv0tdBTrXHWyCsi
JXhISf8mo4joTwqCQRqGaOVCaKVFQbLiAmnS3SRueVeE2EjGbMb1lHlNjVKUxlcU
gfn9TVaW5sjMCrvYVSsNrWiCHZoUH3+vxa75MYiANl8iCH3l59Q4Oq1jE0cdu3Aj
t2xrB2LVivJefVu/9yV2jyApg7+lQTq+po7HCk6ihw5GWVxjEkC8Tez+CqlEGT6c
VLmBzM0fsmDSbglLJ4vO+sB0wAVKjwZ5KzMHvGP10K359N2kfS1ASTliam6UtPGu
kiZRPrgH/24OQqOH0fZZrOJX397D8vD8b/dtrZZkLJHjPdB2Zk3Gv4R7Rsb2datN
E3i7G6b11IguDa7nDeq1Zpi8gyEse/iBjn5ZbN3+DsGxtNa5DgI5pOilyTzjimpp
3RPOqRH+FPnBv1/Q50IkST3idk5OQCNxJdfj63BEAC3zK07UrvhCIAXV+ggB/dc5
hxj0dLmMXSoRS26kQ9zpiFI+bdvL8KDXrOnTnHA+6psJq+s64OA=
=TIA+
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.