We have finally started playing with maybe
expression EEP 49 and we have noticed that they do not support guards. For example, I may want to write:
begin
{ok, Int} when Int > 0 ?= expr(),
Int
end.
One could argue that the above could be rewritten as:
begin
{ok, Int} ?= expr(),
true ?= Int > 0,
Int
end.
But remember guards have specific semantics in relation to errors that would be annoying for the developer to manually replicate.
EEP 49 does not mention guards in this context, so it is not possible to know if this aspect was considered (and then discarded) or not. I can think of two concerns about supporting guards here.
First, the AST currently does not have a place to put guards:
{'maybe',1,
[{maybe_match,1,
{cons,1,{var,1,'X'},{nil,1}},
{cons,1,{integer,1,1},{nil,1}}},
{var,1,'X'}]}
Unless guards are expressed as an operator, which is not done anywhere else in the AST.
The punctuation for multiple guards in Erlang can be confusing. Take this example:
begin
{ok, Int} when Int > 0, Int < 0 ?= expr(),
Int
end.
One option is to require parenthesis in such cases:
begin
({ok, Int} when Int > 0, Int < 0) ?= expr(),
Int
end.
Any thoughts, concerns, or alternatives?