-
Notifications
You must be signed in to change notification settings - Fork 14
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 guards are not a sufficient replacement for view patterns #174
Comments
This is most likely a consequence of two historical coincidences:
Now that pattern synonyms are a thing (and that we have
Perhaps there are other solutions I haven't thought of as well. What are your thoughts on this, @goldfirere? |
Why couldn't option 3 just define |
Ah, great point! For some reason, I had it in my mind that the thing to the left of the pattern P2 x y <- ((\(x', y') -> (f x', g y')) -> (x, y)) That should work pretty nicely, I think. I like it. |
It occurs to me that this approach could also resolve another restriction that pattern P x y z <- (\x' -> case x' of (y', z') -> (x', y', z')) (x, y, z) |
That's easy to implement using pattern P x a b <- (\arg_2_0 -> case arg_2_0 of
Foo a b -> GHC.Tuple.(,,) a b (Foo a b) -> GHC.Tuple.(,,) a b x) |
ok, there's a (unneatened) PR for this. aside: It's a shame that th-desugar doesn't use lambdacase to replace |
For what it's worth, I encountered another situation in which it would be nice to use |
The implementation for desugaring view patterns is
dsPat (ViewP _ _) = dsPat (ViewP _ _) = fail "View patterns are not supported in th-desugar. Use pattern guards instead."
It's not possible to use pattern guards in pattern synonyms, so desugaring the following will fail:
And of course it's not possible to construct such pattern synonyms!
There's definitely a complexity/usefulness tradeoff to be struck; although I'd like to be able to use view patterns with th-desugar I would understand if this is closed with something like "not worth the complexity".
The text was updated successfully, but these errors were encountered: