#5144: Pattern synonyms
---------------------------------+------------------------------------------
    Reporter:  simonpj           |        Owner:              
        Type:  bug               |       Status:  new         
    Priority:  normal            |    Milestone:  _|_         
   Component:  Compiler          |      Version:  7.0.3       
    Keywords:                    |     Testcase:              
   Blockedby:                    |   Difficulty:              
          Os:  Unknown/Multiple  |     Blocking:              
Architecture:  Unknown/Multiple  |      Failure:  None/Unknown
---------------------------------+------------------------------------------
 Lennart would like pattern synonyms.  Something like
 {{{
 pattern con var1 … varN = pat
 }}}
 where ‘pattern` is a new keyword.
  * Perhaps there should be a way to give a type as well, so the `con`
 could be `(con :: type)`.
  * The `rhs` is type checked as a usual pattern, i.e., in the global
 environment.
  * The `pat` should bind exactly `var1` .. `varN`.
  * Recursive pattern synonyms are not allowed.

 With `con` in scope it can be used like any other constructor in a
 pattern, and the semantics is simply by expansion.

 It would have been very nice if `con` could be used in expressions as
 well, but I don’t see how that could work with view patterns.
 Perhaps view patterns could be extended to make them bidirectional.

 My rationale for wanting pattern synonyms is that I sometimes have pattern
 matching with a lot of complex repetition in them.
 I’ve even resorted to using CPP in the past, and that just shows that
 Haskell is lacking some abstraction mechanism.

 If pattern synonyms could be made to work in the presence of view pattern
 it would offer a mechanism for normal pattern matching on abstract types,
 since the abstract type could export some pattern synonyms and you’d not
 be able to tell of those were real constructors or not.

 I’ve not tried implementing this, but I think SHE has something like it.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to