Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative numbers in pattern matches are syntax errors #1261

Open
rtfeldman opened this issue Jan 14, 2016 · 8 comments
Open

Negative numbers in pattern matches are syntax errors #1261

rtfeldman opened this issue Jan 14, 2016 · 8 comments

Comments

@rtfeldman
Copy link
Member

This is an sscce version of #1259

f x =
  case x of
    1 -> "ok"
    -1 -> "breaks parsing"
    _ -> "ok"

Gives a syntax error.

If you swap the -1 pattern with the previous line, everything compiles, so the problem seems to affect only patterns after the first one.

@yawaramin
Copy link

Workaround: wrap the -1 in parens: (-1).

@evancz
Copy link
Member

evancz commented May 12, 2016

Thanks for the SSCCE. Follow along in #1374

@evancz evancz closed this as completed May 12, 2016
@evancz evancz changed the title Negative numbers in pattern matches are syntax errors after the first pattern Negative numbers in pattern matches are syntax errors Dec 18, 2016
@evancz evancz reopened this Dec 18, 2016
@evancz
Copy link
Member

evancz commented Dec 18, 2016

Okay, making this it's own thing again because all the other things in the meta issue are done.

For my future reference: I think it should only be possible to match on Int and I'm not sure if there are any languages that permit negative numbers in matches.

@JoeyEremondi
Copy link
Contributor

Haskell allows it if it's parenthesized:

\(-3) -> 1 works on tryhaskell.org, but \-3 -> 1 gives a parse error.

OCaml works with or without parenthesis.

@yawaramin
Copy link

F# (and Fable) and Scala (Scala.js) allow negative numbers in patterns as well.

@crazymykl
Copy link

Rust also allows negatives: https://play.rust-lang.org/?gist=017c59b66ce0a3b5f080dad3cf9d2999&version=stable&mode=debug&edition=2015 .

@aecay
Copy link

aecay commented Sep 7, 2018

An update for 0.19: the workaround at #1261 (comment) no longer works. As far as I can tell, negative numbers aren't allowed in pattern matches as either the first or non-first pattern, and the presence/absence of parentheses does not make them allowed either.

@lydell
Copy link
Contributor

lydell commented Sep 7, 2018

@aecay See also #1773

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants