-
Notifications
You must be signed in to change notification settings - Fork 43
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
Proposal 869: pattern-matching syntax #908
Conversation
@Emanon42 while I remember it, for consistency we should probably change all occurrences of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good now. My main suggestion besides whitespace nitpicking is to make get_normal_funlit
into a library function and use it in more places to avoid repetition (and save effort if we ever later refactor the funlit cases). Otherwise looks ready to merge.
Looks like put |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing all these revisions, @Emanon42! It was good working with you during your internship.
I've got a few final comments, but all of the major things have been addressed now. I'd be happy for this to go in.
Hmm, the CI is failing due to the documentation not building for some reason - maybe a transient problem? (this only happens on Travis so it might be a Travis problem). @dhil, any further remarks before this gets merged? It seems that your most recent review comments have been addressed. |
It seems that anonymous switch functions are not being desugared properly:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I will merge this in shortly.
let name_list = List.map (fun pat -> (pat, Utility.gensym())) patterns in | ||
let switch_tuple = List.map (fun (_, name) -> with_pos (Var name)) name_list in | ||
(* assemble exhaustive handler *) | ||
let exhaustive_patterns = with_pos (Pattern.Any) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This pattern/case may be redundant, though, currently we do not check for redundancy or exhaustiveness of patterns.
Congratulations, @Emanon42! |
Thanks again for mentoring me! It is really happy to work with you all. |
This patch implements named and anonymous switch functions, which provide convenient syntax for defining functions on a case-by-case basis on their input. Closes links-lang#869.
This pull request implements #869
To enable this syntax sugar, set
pattern_matching_sugar=true
in configSyntax
It adds syntax of SML-style pattern-matching like that:
Semantics
Desugaring the cases defined in pattern-matching function to a
Switch
phrase and adding a wild card case to raise an error to handle the non-exhaustive case (with position of wrong code).