[m-users.] Announcement (aggregates module) + questions (window functions)

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Mar 6 16:09:18 AEDT 2023



On Sat, 4 Mar 2023 15:26:31 +0000, Mark Clements <mark.clements at ki.se> wrote:
> As a follow-up: when should one use non-determinism and when should one use Mercury?

Sorry, I do not understand this question. Mercury supports non-determinism, so
those two things are not mutually exclusive.

> To motivate my questions: I came to Mercury because I was looking for a typed "Prolog"
> that allowed for elegant joins between relationships (essentially to replace SQL:).

Pretty much any logic programming language can be used to implement joins.
But whether a join is the right approach to solve a problem depends on the problem,
and even then, it can be (and in this case, is) a question of taste whether
a join-based approach is better than a non-join-based approach.

In your original code, what I was objecting to was NOT the nondeterminism.
What I was objecting to was

- baking the data to be operated on into the program, which made
  the program totally inflexible; and

- the use of nested lambda expressions, especially when the
  inner lambda expressions seem to be redundant.

> Zoltan's implementation for the CSV example is canonical and efficient code -
> but it is also comparatively long

Both my point and (I am pretty sure) Richard's point is that what matters
is the code's *readability*, and not its *length*.

> and uses several data structures

If those structures, including the definitions of their types, and
(in a real application) the documentation of those type definitions
help readers understand what the code is doing, which I think
was the case in my program, then these structures improve
the code, and you shouldn't *want* to replace them.

> that could be
> replaced by less efficient non-determinism.

Even disregarding the point above, why would that be an advantage?

> When is the elegance of a non-deterministic solution acceptable given its inefficiency?

This question makes the implicit assumption that a non-deterministic
solution is inherently more elegant than a deterministic solution.
I don't believe that assumption is justified. For some problems,
the assumption may be true; for other prblems, it may be false.
For this problem, both Richard and I think it is false.

As for when a less efficient solution is acceptable, the answer is
obvious: when profiling and/or analysis shows that the
inefficiency does not matter.

Zoltan.


More information about the users mailing list