New pattern matching doc

Mark Raynsford mark at io7m.com
Thu Jan 14 21:09:09 UTC 2021


On 2021-01-06T15:52:19 -0500
Brian Goetz <brian.goetz at oracle.com> wrote:

> I have pushed
> 
> https://github.com/openjdk/amber-docs/blob/master/site/design-notes/pattern-match-object-model.md
> 
> to the amber-docs repo, which outlines the direction for how patterns 
> fit into the object model.

I've been following along with the discussion on patterns and guards,
and I have a concern that I didn't anticipate: The practicality of
using patterns to _parse_. Mostly, I'm eyeing "A possible approach for
parsing APIs" [0].

The issue, as I see it, is that I'm not entirely sure if a failure to
match in such a large nested structure is going to help me construct
a usable _error message_. As you're certainly aware, about 80% of the
code in any good compiler is devoted to giving error messages that are
actually useful to users. If I get a parse error, for example, I want to
know - down to the level of lines and columns - which part of the input
failed to match expectations.

Is matching a structure like that going to be able to provide useful
error messages if input _doesn't_ match? It seems like it just provides
a binary true/false answer. If it's the case that it won't actually
help with giving useful error messages, then I think that reduces the
applicability of patterns to this particular class of problems. It
follows that it also might mean that the nice things we're putting on
top (such as the composition of patterns) won't actually see practical
use, because people end up writing very simple patterns with at most
one level of nesting.

Now, you know me, I'm the first to try to apply pattern matching and
algebraic data types to any and every problem. I'm a little concerned
about possible over-engineering though.

[0]https://github.com/openjdk/amber-docs/blob/master/site/design-notes/pattern-match-object-model.md#a-possible-approach-for-parsing-apis

-- 
Mark Raynsford | https://www.io7m.com



More information about the amber-spec-experts mailing list