From 1e8299da4982f7193f3ed5cc54c9996c6f7f1a14 Mon Sep 17 00:00:00 2001 From: Vesa Karvonen Date: Thu, 13 Feb 2020 07:30:46 +0200 Subject: [PATCH] Add `(type _)` as an allowed pattern Previously a hole, `_`, was not allowed in place of the name of a `(type x)` pattern. --- parser.mly | 7 +++---- regression.1ml | 4 ++++ syntax.ml | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/parser.mly b/parser.mly index 1bc417ba..6d205c2b 100644 --- a/parser.mly +++ b/parser.mly @@ -381,16 +381,15 @@ bind : atpat : | head - { if $1.it = "_" then holeP@@at() else varP($1)@@at() } + { headP $1 } | LBRACE decon RBRACE { strP($2)@@at() } | LPAR RPAR { strP([])@@at() } | LPAR patlist RPAR { match $2 with [p] -> p | ps -> tupP(ps)@@at() } - | LPAR TYPE name typparamlist RPAR - { annotP(varP($3.it@@ati 3)@@ati 3, - funT($4, TypT@@ati 2, Pure@@ati 2)@@at())@@at() } + | LPAR TYPE head typparamlist RPAR + { annotP(headP $3, funT($4, TypT@@ati 2, Pure@@ati 2)@@at())@@at() } ; apppat : | atpat diff --git a/regression.1ml b/regression.1ml index 7131a14b..024bbb33 100644 --- a/regression.1ml +++ b/regression.1ml @@ -28,6 +28,10 @@ Equivalence: { ;; +hole_is_allowed_type_pattern (type _ _) = (); + +;; + type_error { type_error 101 }; ;; diff --git a/syntax.ml b/syntax.ml index 666bd84d..f7434a88 100644 --- a/syntax.ml +++ b/syntax.ml @@ -251,6 +251,9 @@ let varP(x) = VarB(x, VarE("$"@@x.at)@@x.at)@@x.at, None let holeP : bind * typ option = EmptyB@@nowhere_region, None +let headP id = + if id.it = "_" then holeP@@id.at else varP(id)@@id.at + let asTopt(to1, to2) = match to1, to2 with | None, None -> None