You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letpexp_tuple~locl=match l with [ x ] -> x |_ -> pexp_tuple ~loc l
letppat_tuple~locl=match l with [ x ] -> x |_ -> ppat_tuple ~loc l
letptyp_tuple~locl=match l with [ x ] -> x |_ -> ptyp_tuple ~loc l
letpexp_tuple_opt~locl=
match l with[] ->None|_ :: _ ->Some (pexp_tuple ~loc l)
letppat_tuple_opt~locl=
match l with[] ->None|_ :: _ ->Some (ppat_tuple ~loc l)
I wonder if it makes sense to also have a special case for the empty list, degrading to () instead. Right now calling them with the empty list yields an error from deeper down that a tuple needs at least 2 elements.
Or maybe there's a reason this generalization hasn't been made? The existence _opt versions of these functions hints at the need to distinguish the empty list case.
The text was updated successfully, but these errors were encountered:
Thanks for the issue! I wasn't sure myself, so I've just had a look at the compiler Parsetree module. There are few Parsetree invariants that aren't enforced by the type checker. They're written down as comments in the compiler Parsetree module. There's one for Pexp_tuple: n>=2. That explains the behavior of ppat_tuple and why ppat_tuple_opt exists.
It would be quite valuable to add documentation about that in Ast_builder though. Do you want to do that?
Ast_builder.Default.pexp_tuple
, etc. currently have a special case for the one-element list:ppxlib/src/ast_builder.ml
Lines 91 to 99 in 6baf858
I wonder if it makes sense to also have a special case for the empty list, degrading to
()
instead. Right now calling them with the empty list yields an error from deeper down that a tuple needs at least 2 elements.Or maybe there's a reason this generalization hasn't been made? The existence
_opt
versions of these functions hints at the need to distinguish the empty list case.The text was updated successfully, but these errors were encountered: