Pattern synonym thoughts

David Feuer david.feuer at gmail.com
Thu Feb 25 02:58:14 UTC 2016


There are two features I think would make pattern synonyms even nicer:

1. If a pattern synonym is defined in the same module as one of the type
constructors in the type of thing it matches, then it should be possible to
export it "attached" to one or more of those constructors (normally but not
necessarily the outermost one g. An example of how this might look:

module Foo (A (.., S))
data A = X | Y
pattern S = X

Someone writing a module importing Foo wouldn't even need to know that S
was a pattern synonym--they'd just

import Foo (A (..))

and be done with it. The (.., S) here means "export all A's constructors,
along with the pattern synonym S".

2. Pattern synonym groups

This vague idea attacks a long-standing efficiency concern. It's not fully
formed in my mind, but I'd love to be able to write groups of pattern
synonyms that all use a *guaranteed shared* computed view of the underlying
structure. Once the first synonym in the group is encountered, the view is
calculated and held until the pattern match completes or the last synonym
in the group is rejected.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20160224/686ddd38/attachment.html>


More information about the ghc-devs mailing list