[m-users.] Correct use of solutions.

Sean Charles (emacstheviking) objitsu at gmail.com
Sat Jul 29 18:27:06 AEST 2023


I've been trying to produce a simple list of strings to output as the response to a command line argument request to list the supported targets of my transpiler, given I have a type and a predicate to return the printable string for the language I thought solutions/2 was my answer, but not so far! Again, it's a mixture of the terminology to my untutored brain and the lack of any really clear guiding examples, in Prolog this stuff is trivial!


    % Does -T / --targets.
    %
:- type supported_target
    --->    language_c
    ;       language_python
    ;       language_pythont
    ;       language_js.

:- pred show_targets(io::di, io::uo) is det.

300:show_targets(!IO) :-
301:    io.format("Available target languages:", [], !IO),
302:    solutions(
303:       (pred(A::out) is nondet :-
304:            target_name(_, A)
305:        ),
306:       Targets
307:    ),
308:    io.print_line(Targets, !IO).



:- pred target_name(supported_target, string).
:- mode target_name(in, out) is det.

target_name(language_c, "Vanilla C").
target_name(language_python, "Vanilla Python").
target_name(language_pythont, "Typed Python").
target_name(language_js, "Vanilla JavaScript").

gives me the follwiong output:

command_line.m:308: In clause for `show_targets(di, uo)':
command_line.m:308:   mode error in conjunction. The next 3 error messages
command_line.m:308:   indicate possible causes of this error.
command_line.m:308:
command_line.m:303:   In clause for `show_targets(di, uo)':
command_line.m:303:   mode error in conjunction. The next 2 error messages
command_line.m:303:   indicate possible causes of this error.
command_line.m:303:
command_line.m:304:   In clause for `show_targets(di, uo)':
command_line.m:304:   in argument 1 of call to predicate
command_line.m:304:   `command_line.target_name'/2:
command_line.m:304:   mode error: variable `V_5' has instantiatedness `free',
command_line.m:304:   expected instantiatedness was `ground'.
command_line.m:303:
command_line.m:303:   In clause for `show_targets(di, uo)':
command_line.m:303:   in argument 1 of clause head:
command_line.m:303:   mode error in unification of `LambdaHeadVar__1' and `A'.
command_line.m:303:   Variable `LambdaHeadVar__1' has instantiatedness `free',
command_line.m:303:   variable `A' has instantiatedness `free'.
command_line.m:308:
command_line.m:302:   In clause for `show_targets(di, uo)':
command_line.m:302:   in call to predicate `solutions.solutions'/2:
command_line.m:302:   mode error: arguments `V_12, Targets' have the following
command_line.m:302:   insts:
command_line.m:302:     free,
command_line.m:302:     free
command_line.m:302:   which does not match any of the modes for predicate
command_line.m:302:   `solutions.solutions'/2.
command_line.m:302:   The first argument `V_12' has inst `free', which does not
command_line.m:302:   match any of those modes.
command_line.m:308:
command_line.m:308:   In clause for `show_targets(di, uo)':
command_line.m:308:   in argument 1 of call to predicate `io.print_line'/3:
command_line.m:308:   mode error: variable `Targets' has instantiatedness
command_line.m:308:   `free',
command_line.m:308:   expected instantiatedness was `ground'.


I've read the mercury crash course site with it's 'rows()' but so far drawn a blank...just how simple is it to get a list of possible solutions so that I may print a list of strings representing supported languages?

Thanks.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20230729/77e5872e/attachment.html>


More information about the users mailing list