[GHC] #10928: Refine pattern synonym signatures

GHC ghc-devs at haskell.org
Tue Oct 6 12:56:37 UTC 2015


#10928: Refine pattern synonym signatures
-------------------------------------+-------------------------------------
        Reporter:  mpickering        |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.0.1
       Component:  Compiler          |              Version:  7.10.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  Other             |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
-------------------------------------+-------------------------------------

Comment (by rwbarton):

 One thing that bothers me about the current syntax is that `C1 a => C2 a
 => T a` in general already has a meaning. It's the same thing as `(C1 a,
 C2 a) => T a`. I don't know if this is actually valid Haskell 98 (I
 suspect not), but GHC accepts it without any language flags.

 Just to throw out another option, long ago user "ski" on IRC suggested a
 syntax for existentials-plus-constraints, dual to constrained polymorphic
 values. The idea is dual to
 {{{
 forall a. C a => T a
 }}}
 which is a sort of function that accepts a `C a` constraint and produces a
 value, we have
 {{{
 exists a. C a *> T a
 }}}
 which is a sort of pair of a `C a` constraint (dictionary) and a value.
 (Mnemonic: `*` is like a pair and `>` is from `=>`. Not sure I am
 convinced myself.)

 I'm not sure whether this applies directly to pattern synonyms since a
 pattern is not really the same thing as a value. But, we could at least
 use the idea of two different bits of syntax for provided and required
 constraints, e.g.,
 {{{
 pattern P :: (Eq a, Num a) => (Show a, Show b) *> b -> T a
 }}}
 Here I am thinking of `(Eq a, Num a)` as in negative position and `(Show
 a, Show b)` in positive position, so tentatively using the corresponding
 `=>` and `*>`.

 Advantages:

 * Does not use syntax that already has another meaning (`C1 a => C2 a => T
 a`)

 * You can write patterns with either empty required constraints or empty
 provided constraints (`Cr a => T a`, `Cp a *> T a`) without having to add
 an empty context

 * Not extremely verbose like Richard's verbose syntax

 Disadvantages:

 * Another funny bit of syntax to learn. But at least it appears in only
 one context.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10928#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list