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

Pattern Synonyms #1667

Closed
paf31 opened this issue Nov 24, 2015 · 2 comments
Closed

Pattern Synonyms #1667

paf31 opened this issue Nov 24, 2015 · 2 comments

Comments

@paf31
Copy link
Contributor

paf31 commented Nov 24, 2015

No description provided.

@natefaubion
Copy link
Contributor

As a reference in this space, what about something like F# active patterns?

@rgrempel
Copy link

rgrempel commented May 9, 2016

In working on purescript-elm, I've come across two cases in which pattern synonyms would be nice (if I'm understanding correctly what pattern synonyms would be -- here's a reference to an older issue, called "Constructor alias" #1438).

One case is Elm's Result type, which is basically equivalent to Data.Either, but using Ok and Err as the two constructors, rather than Left and Right.

Ordinarily, I'd want to implement Result as an alias for Either, and then write whatever functions are needed to wrap the API differences. However, it's not really possible to alias the constructors. (I know I can now have operator aliases for the constructors, and even use them in pattern matching (#1890), which is neat, but doesn't allow for Ok and Err). So, I end up re-implementing the whole thing (basically copying the code for Either and renaming the constructors).

The other case is Elm's Date type. Like Data.Date, it has an type for enumerating the days of the week. Now, they are named differently -- Day in Elm vs. DayOfWeek in Purescript. Of course, I can alias Day to mean DayOfWeek easily enough. However, the Elm constructors are abbreviated ... i.e. Mon, Tue, Wed vs. Monday, Tuesday, Wednesday in Data.Date. Without pattern synonyms (or constructor aliases), I don't think there's anything I can do about that.

So, those are cases in which I would have found pattern synonyms (or constructor aliases) to be helpful.

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

3 participants