[GHC] #8581: Pattern synonym used in an expression context could have different constraints to pattern used in a pattern context (was: Add support for explicitly-bidirectional pattern synonyms)

GHC ghc-devs at haskell.org
Fri Dec 18 20:21:09 UTC 2015


#8581: Pattern synonym used in an expression context could have different
constraints to pattern used in a pattern context
-------------------------------------+-------------------------------------
        Reporter:  cactus            |                Owner:
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.0.1
       Component:  Compiler          |              Version:
      Resolution:                    |             Keywords:
                                     |  PatternSynonyms
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by mpickering):

 * cc: douglas.mcclean@… (removed)
 * blockedby:  5144 =>


Old description:

> Some patterns cannot, by themselves, be turned over into an expression,
> so they have to be defined as unidirectional. Maybe the most trivial
> example would be
>
> {{{
> pattern P -> _
> }}}
>
> Sometimes, however, it would be desirable to give an explicit way of
> turning these pattern synonyms into expressions. The PatternSynonyms wiki
> page has this example:
>
> {{{
> import qualified Data.Sequence as Seq
>
> pattern Empty -> (Seq.viewl -> Seq.EmptyL)
> pattern x :< xs -> (Seq.viewl -> x Seq.:< xs)
> pattern xs :> x -> (Seq.viewr -> xs Seq.:> x)
>
> }}}
>
> It would make a ton of sense to be able to use this cons/snoc notation as
> "constructors" for `Seq`s.
>
> The proposed syntax for this
>
> {{{
> pattern x :< xs -> (Seq.viewl -> x Seq.:< xs) where
>     x :< xs = x Seq.<| xs
> }}}

New description:

 > The two directions of an explicitly-bidirectional pattern might have
 utterly different class constraints. After all, the two directions are
 specified by quite different code. Suppose that

 > * Pattern `P` (used in a pattern) requires constraints `CR`, and
 provides constraints `CP`
 > * Constructor `P` (used in an expression) requires constraints `CE`
 >
 > Then I think the only required relationship is this: `CP` must be
 provable from `CE` (since CP is packaged up in a P-object).

 Currently, `CE := CP + CR.

--

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


More information about the ghc-tickets mailing list