#2399: Template Haskell: support for view patterns
------------------------------+---------------------------------------------
Reporter: fons | Owner:
Type: feature request | Status: new
Priority: low | Milestone: _|_
Component: Template Haskell | Version: 6.9
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Architecture: Unknown
Os: Unknown |
------------------------------+---------------------------------------------
Comment (by simonpj):
Ah I see. I'd missed the quasiquoter connnection.
One way to fix this would be to add view patterns to TH. But it made me
wonder: why aren't pattern guards compositional? At the moment they are
resolutely top-level. And, as you say, not part of patterns. But syntax
aside it would make perfect sense to make them part of a pattern:
{{{
pat ::= var | C pat1 ... patn
| pat|quals
}}}
where `qual` is a pattern-guard "qualifier". So (again, syntax aside) you
could write
{{{
f (x | x>3) = ...
g ([y] | Just z <- lookup y) = ...
}}}
That would push pattern guards into the syntax of patterns. Now view
patterns are syntactic sugar:
{{{
(exp -> pat) means (x | pat <- exp x)
where x is fresh
}}}
The reverse encoding is also possible
{{{
(pat | quals) means (f -> Just (v1,...,vn))
where
(v1,...,vn) are the variables bound by pat
f pat | quals = Just vs
}}}
I'm not sure I'm advocating this (yet!), but I hadn't thought of it before
so I thought I'd jot it down.
If TH users agree about just how to beef up patterns, I'm not against
adding it. I'm just a bit conscious that view patterns are experimental
and the more concrete we pour the harder it becomes to change.
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2399#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs