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

Parser does not allow literal patterns #2017

Closed
Munksgaard opened this issue Sep 8, 2023 · 3 comments
Closed

Parser does not allow literal patterns #2017

Munksgaard opened this issue Sep 8, 2023 · 3 comments

Comments

@Munksgaard
Copy link
Collaborator

According to the language reference, Futhark allows literals as patterns, meaning that the following code should be accepted:

def foo 1 = 1

However, the current parser does not allow this:

Error at program.fut:1:9-9:
Unexpected token: '1'
Expected one of the following: '='

If you find this error message confusing, uninformative, or wrong, please open an issue:
https://github.com/diku-dk/futhark/issues

Playground link

@athas
Copy link
Member

athas commented Sep 8, 2023

Two solutions are possible: either change the grammar in the language reference, or allow this in the parser and instead fail during type checking.

The reason for this is that we don't want to allow refutable patterns in let bindings and function parameters. However, that also means we currently don't allow things like def f (#foo x) = ... where #foo is from a single-constructor type. That hardly comes up frequently, but we might want to allow it.

@Munksgaard
Copy link
Collaborator Author

Wouldn't allowing literals in function definition patterns introduce ambiguity here:

def a - 1 = 2

That could be interpreted both as an infix binding of the - operator or as a function a that matches only on the literal pattern -1.

@athas
Copy link
Member

athas commented Sep 8, 2023

We just pick one of them, and since this would be rejected in the type checker anyway, the distinction is not important.

athas added a commit that referenced this issue Nov 9, 2023
@athas athas closed this as completed in 558c8e3 Nov 10, 2023
0undefined pushed a commit to 0undefined/futhark that referenced this issue Nov 13, 2023
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

2 participants