[m-users.] Determinism woes...
Julian Fondren
jfondren at minimaltype.com
Fri Jul 5 13:56:00 AEST 2019
On 2019-07-04 17:46, emacstheviking wrote:
> Thanks Richard!
>
> That is so obvious when you see it. I am thinking like a Haskell
> hacker this evening for sure.
> I changed it to "cc_multi" and it compiled ANd did what I expected /
> wanted.
It may do you what you want, but this is by accident. It is legal for
the cc_multi version of your code to report that '(' is a c_general
rather than a p_open.
Consider:
https://mercurylang.org/information/doc-latest/mercury_ref/Semantics.html
Or this chapter of the Prolog to Mercury guide:
https://mercurylang.org/information/doc-latest/mercury_trans_guide/Commits.html
I don't know Prolog well at all, and wouldn't've benefited from that
chapter since I'm not familiar with that pattern of cuts and a
catch-all, but I've run into your exact problem of wanting to say
char_type(')', p_open).
char_type('(', p_close).
char_type(_, c_general).
because functional languages with pattern-matching all do it in an
ordered way that permits very similar constructs. This is probably
what you meant by "thinking like a Haskell hacker" but even C's
switch() statement permits this sort of thing. For Mercury you can try
viewing your code through the lens of the strict commutative
semantics.
So when looking at that code, imagine
char_type(_, c_general).
char_type(')', p_open).
char_type('(', p_close).
or
char_type(')', p_open).
char_type(_, c_general).
char_type('(', p_close).
or
char_type('(', p_close).
char_type(_, c_general).
char_type(')', p_open).
...
If any variation doesn't look like something you'd want, your original
code isn't what you want either.
More information about the users
mailing list