Re: [m-users.] Correct use of solutions.

Mark Brown <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <CAM4AczB4Byiur_8gBUXOYn_Wkas0YXZ7wRMLN-E=ZiZFRZf3mw@mail.gmail.com>
On Sat, Jul 29, 2023 at 6:27 PM Sean Charles (emacstheviking)
<[email protected]> wrote:
>
> 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!

In Prolog this stuff is usually *concise*, but I wouldn't call it
trivial. To verify correctness of bagof, for example, you need to
reason about binding patterns and determinism. In the case of
solutions/2, Mercury is doing a lot of the work for you, as well as
for people reading your code, but like a lot of things in Mercury the
benefits come at the cost of restricting yourself to mode-correct code
and declaring what you are doing.

Whether verifiability is more important than brevity depends on your
project, of course. Personally I find thinking to be more of a
bottleneck than reading or typing, so it's usually a higher priority.
But maybe that is just me!

Cheers,
Mark

>
>
>     % 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.
>
> _______________________________________________
> users mailing list
> [email protected]
> https://lists.mercurylang.org/listinfo/users
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
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.