[m-users.] Why can't `det` be used where `multi` is expected.
Philip White
philipwhite at cedarville.edu
Mon Aug 5 14:02:07 AEST 2019
The type [get_opt.option_ops] provides a choice between [option_ops] and
[option_ops_multi], both of which contain short, long, and default
option predicates. The difference is that [option_ops] expects the
predicate for default option values to be [nondet], but
[option_ops_multi] expects it to be [multi].
Below, my predicate, [option_default/2], is declared as [multi], and
this whole program compiles. However, [option_default/2] is clearly
deterministic, and indeed the compiler warns that I could be more
specific. However, if I take the suggestion, then I get nasty
instantiatedness errors. It would seem to me that passing a
deterministic predicate into a place which expects a [multi] predicate
is always valid. What am I not understanding?
```
:- module mds.
:- interface.
:- import_module io.
:- pred main(io.state::di, io.state::uo) is det.
%------------------------------------------------------------------------------%
:- implementation.
:- import_module getopt, bool.
:- pred write_stars(io.state::di, io.state::uo) is det.
write_stars(!IO) :-
io.write_string("********************************************************************************\n", !IO).
main(!IO) :-
io.command_line_arguments(Argv, !IO),
OptionOps = option_ops_multi(short_option, long_option, option_default),
getopt.process_options(OptionOps, Argv, Options, GetoptResult),
io.write(Argv, !IO),
io.write(Options, !IO),
io.write(GetoptResult, !IO),
io.nl(!IO),
io.write_string("\n", !IO).
:- type option ---> stars.
:- pred option_default(option::out, option_data::out) is multi.
option_default(stars, bool(yes)).
:- pred short_option(character::in, option::out) is semidet.
short_option('s', stars).
:- pred long_option(string::in, option::out) is semidet.
long_option("stars", stars).
```
More information about the users
mailing list