-
Notifications
You must be signed in to change notification settings - Fork 26
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
Pattern Matching & String Fixes #330
Conversation
I have looked at the PR and it seems fine. However, I would suggest to add a test that checks these two fixes. |
May I suggest two tests? :) |
sorry, a few nights without much sleep! +1 |
Tests added! |
@glundi I am pretty sure you know what |
Oki, renamed the tests. I'm not sure why the checks suddenly fail now though. There doesnt seem to be anything new upstream for me to merge. Edit: Nvm |
…h string objects in match expressions
Is it expected to re-bind already bound variables (namely
This example prints the value |
There are two reasons for that design.
|
@kikofernandez The inner x is a binding occurrence and it overrides the outer x. This is fairly standard lexical scoping. If you want to access the outer x, rename the inner x. |
@supercooldave yes, I know. It's the same in Haskell. I was wondering if we want to keep it that way. It seems like we want |
Pattern Matching & String Fixes
@kikofernandez. I can't see the alternative being better. But I've been ruined by Haskell. |
Well, Kikos interpretation would allow you to more easily match for equality against already defined variables. I.e. this:
instead of this:
|
I didn't read PR, but I feel @glundi's first code example is the less surprising one. I would rather to see the first instead of the second. |
I definitely prefer the second one to the first one! This way you always get the same results from a variable pattern (bind a value to a name) instead of sometimes getting an implicit equality check. |
The reason I prefer the second one is that it future proofs Encore for matching on function heads. Matching on function heads clearly should follow the same rules as regular matching (and would probably be implemented as some desugaring), functions should also behave the same regardless of how many heads they have.
Clearly x should introduce a new binding. Wouldn't it be confusing if it didn't also do so in this example as well?
If we pick the first interpretation in my previous post, then this second |
Fixes pattern matching to work with the new string objects.
Also fixes a bug that caused an incorrect type error when the pattern handlers were of different types but with a common super type.