Ticket #2399 (closed feature request: fixed)
Template Haskell: support for view patterns
| Reported by: | fons | Owned by: | igloo |
|---|---|---|---|
| Priority: | low | Milestone: | _|_ |
| Component: | Template Haskell | Version: | 6.11 |
| Keywords: | Cc: | rwbarton@…, audreyt@…, duncan2nd@…, reiner.pope@…, id@…, vogt.adam@… | |
| Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
| Type of failure: | None/Unknown | Difficulty: | Unknown |
| Test Case: | Blocked By: | ||
| Blocking: | Related Tickets: |
Description
TH's Pat type doesn't include a constructor for view patterns, which would ceratinly be useful.
As an example, Reid Barton suggested using view patterns for creating a regular expression quasiquoter (rx) [1].
For example, to check if a string matches certain regular expresion:
example x = case x of [$rx|.*foo.*] -> "contains foo" _ -> "doesn't contain foo"
Using pattern views, the quasiquoter would expand to
example x = case x of ((=~".*foo.*")->True) -> "contains foo" _ -> "doesn't contain foo"
[1] http://www.haskell.org/pipermail/template-haskell/2008-June/thread.html#669
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

