[m-users.] use of cc_multi.
Zoltan Somogyi
zoltan.somogyi at runbox.com
Sat May 1 07:44:55 AEST 2021
On Fri, 30 Apr 2021 22:30:41 +0100, "Sean Charles (emacstheviking)" <objitsu at gmail.com> wrote:
> write_error(_, _, !_IO).
I would bet that this line is the problem. The other clauses
are effectively a switch on the first argument, which means
at most one of them is applicable, but this clause will be applicable
regardless of what the value of the first argument is.
My guess is that you intended this clause to be a Haskell-style
catchall, to apply in cases where the first argument's value
is not handled by either of the clauses above. Mercury does not
work like that. In Mercury, the right thing to do is to *tell*
the compiler that this clause applies *only* when the first arg
is not one one of plain, simple, json or xml. You can do that
like this:
write_error(ErrorFormat, _, !IO) :-
( ErrorFormat = otherformat1
; ErrorFormat = otherformat2
...
; ErrorFormat = otherformatN
).
This is more work up front than a catchall, but much better
in the long run, because if later someone adds a new errorformat,
they get an error that tells them they have to update this code.
By the way, if you want to know how such code is formatted
by the Mercury project, have a look at check_for_bad_token
in parser.m in the Mercury standard library.
Zoltan.
More information about the users
mailing list