[GHC] #5144: Pattern synonyms

GHC ghc-devs at haskell.org
Sat Aug 10 10:26:07 CEST 2013


#5144: Pattern synonyms
-------------------------------------+------------------------------------
        Reporter:  simonpj           |            Owner:  cactus
            Type:  feature request   |           Status:  new
        Priority:  normal            |        Milestone:  _|_
       Component:  Compiler          |          Version:
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------

Comment (by cactus):

 Progress update:

 Code is in the `pattern-synonyms` branch at
 https://github.com/gergoerdi/ghc.git Until I am ready to submit for
 initial review, I will do all kinds of funky rebasing and history
 rewriting, so use it for read-only snapshots as of now.

 Using the names from the wiki link, pattern-only pattern synonyms and
 simple pattern synonyms now (mostly) work. There's a bug in the typing of
 pattern-synonyms-as-expressions, so e.g. with the following program:

 {{{
 {-# LANGUAGE PatternSynonyms #-}
 pattern One x = [x]

 singleton :: a -> [a]
 singleton x = One x
 }}}

 I get an error that the type of `One` is too rigid; I expect this to be
 easy to fix:

 {{{
     Couldn't match type ‛t0’ with ‛a’
       because type variable ‛a’ would escape its scope
     This (rigid, skolem) type variable is bound by
       the type signature for singleton :: a -> [a]
       at /tmp/PatSyn.hs:18:14-21
     Expected type: [a]
       Actual type: [t0]
 }}}

 The one big missing feature is exporting pattern synonyms. First of all,
 since pattern synonyms are in the namespace of constructors, not types, we
 need special syntax to export them; I propose the following:

 {{{
 module M (pattern P) where

 pattern P x = _:_:x:_
 }}}

 (note that you can have a type called `P` as well, but you'd get a clash
 if you had a constructor with that name).

 To be honest, I have no idea yet how to actually implement exporting,
 since I haven't looked at that part of GHC yet -- any pointers are
 appreciated.

 After I've fixed the bug mentioned and implemented exporting, I'll do a
 formal submission of my (clean-up) patch for review.

 After that baseline, the 'bidirectional pattern synonyms' proposal from
 the wiki page should fit right into it as well. I have no opinion yet how
 difficult adding associated patsyns will be, I'll need to do more research
 first.

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




More information about the ghc-tickets mailing list