[m-rev.] for post-commit review: better diagnostic for missing higher order insts

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed Jul 26 20:01:08 AEST 2023


On 2023-07-26 07:42 +02:00 CEST, "Peter Wang" <novalazy at gmail.com> wrote:
>> I could modify parse_higher_order_mode to return an error indication,
>> instead of the parsed higher order mode, if an option is set. That would
>> allow us to replace all the uses of this shortcut in the library, and therefore
>> in the library manual. Would that be useful?
> 
> Let's hear what other people think.

Given that you agree that omitting the in() wrapper in declarations
is more confusing than helpful, such an option would be useful
to us, at least. I will look into it.

> diff --git a/doc/reference_manual.texi b/doc/reference_manual.texi
> index fb00efe00..d14c4ee3e 100644
> --- a/doc/reference_manual.texi
> +++ b/doc/reference_manual.texi

> + at footnote{If all instances of a given type are expected to use
> +a single inst or a single mode,
> +there is a convention where programmers will give that inst or mode
> +the same name as the type.
> +This works because types, insts and modes belong to separate namespaces
> +so the names do not conflict.

I would add a comma after namespaces.

> +Nonetheless, there is usually no need to define a named mode.
> +It is clearer to write a mode using @samp{in()} or @samp{out()}
> +around a named inst.}
>  
>  The general form of higher order insts follows one of two patterns,
>  one for predicates, and one for functions.
> @@ -6344,6 +6310,34 @@ around any instances of these patterns in Mercury code.
>  @c modes include higher order insts/modes, which would be too complex to
>  @c be useful as an example to novices.
>  
> +As a convenience,
> +the language allows you to write a higher order @emph{mode}
> +using the same syntax as a higher order @emph{inst}.
> +If @var{HOInst} has the form of a higher order inst,
> +then writing @var{HOInst} where a mode is required
> +is the same as writing @samp{in(HOInst)},
> +which is in turn equivalent to @samp{HOInst >> HOInst}.
> +Therefore,
> +you can omit @samp{in()} around the higher order inst of an input argument.
> +For example,
> +
> + at example
> +:- mode foldl(in(pred(in, in, out) is det), in, in, out) is det.
> + at end example
> +
> + at noindent
> +can also be written as
> +
> + at example
> +:- mode foldl(pred(in, in, out) is det, in, in, out) is det.
> + at end example

I think the footnote should be moved here, since
it talks about this construct.

The rest of the diff is fine. Thank you.

Zoltan.


More information about the reviews mailing list