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

Extended patterns #52

Open
gallais opened this issue Apr 10, 2020 · 1 comment
Open

Extended patterns #52

gallais opened this issue Apr 10, 2020 · 1 comment
Labels
bikeshedding enhancement New feature or request shonkier Everything related to the language

Comments

@gallais
Copy link
Member

gallais commented Apr 10, 2020

Gathering here the proposal to extend the pattern-matching language
(for rational patterns, see #43) as well as interesting examples using
the introduced features.

  • intersection patterns p@q matches if p matches and q matches (right-to-left shadowing)

  • union patterns p+q matches if either p matches or if it does not and q matches (usually using | but here it would clash with Cell...)

zip([[]|xs] + [xs|[]]) -> xs
zip([[x|xs] | [y|ys]]) -> [[x|y] | zip([xs|ys])

This example is a bit artificial and requires the function to be uncurried... :/

  • negation pattern !p matches if p does not match (no bindings)
flatten([])                  -> []
flatten([x@!([]+[_|_]) |xs]) -> [x|flatten(xs)]
flatten([x|xs])              -> append(x,flatten(xs))
@gallais gallais added enhancement New feature or request shonkier Everything related to the language bikeshedding labels Apr 10, 2020
@pigworker
Copy link
Contributor

Yes to intersection! Yes to negation! Note that !_ becomes the grumpy pattern.

Union patterns are a tad scarier. It's fun to imagine the type system for them, or even how to scope them. Perhaps p+q binds only those pattern variables which occur in both?

I wonder whether intersection should be & rather than @, or indeed whether /\ and \/ might have some part to play.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bikeshedding enhancement New feature or request shonkier Everything related to the language
Projects
None yet
Development

No branches or pull requests

2 participants