[m-users.] use of cc_multi.

Sean Charles (emacstheviking) objitsu at gmail.com
Sat May 1 07:24:12 AEST 2021


I have a type:

:- type felt_error
    --->    error(
                line   :: int,
                col    :: int,
                pos    :: int,
                file   :: string,
                reason :: string
            ).


I have a predicate to take an instance of one of these and I initially declared it as:

:- pred write_error(options.error_format::in, felt_error::in,io::di, io::uo) is det.

write_error(options.plain, …
write_error(options.simple, …
write_error(options.json, …
write_error(options.xml, …


but it failed to compile saying:

errors.m:028: In `write_error'(in, in, di, uo):
errors.m:028:   error: determinism declaration not satisfied.
errors.m:028:   Declared `det', inferred `multi'.
errors.m:046:   Disjunction has multiple clauses with solutions.


So I thought about it for a bit… what I —want— is for a SINGLE result to match and output my error in the chosen format and the light came on — I have a predicate that —could— return multiple matches (eg solutions calls it) but I only want one of them to match, and then I uttered this sentence to myself and felt very happy, “but I only want one solution, I need it to commit to….  Cc-multi !”

I changed the type to cc_multi and it has compiled just fine but I seek some reassurance that this is the correct reasoning and the correct determinism. If so, I feel like I have made a small but significant advance in my understanding!

Thank you.
Sean.




More information about the users mailing list