[GHC] #7676: Unify patterns and function bindings (was: Conflicting definitions error for simple variable with guards)

GHC cvs-ghc at haskell.org
Sun Feb 10 05:32:52 CET 2013


#7676: Unify patterns and function bindings
----------------------------------------+-----------------------------------
  Reporter:  Mathnerd314                |          Owner:                  
      Type:  feature request            |         Status:  new             
  Priority:  normal                     |      Milestone:                  
 Component:  Compiler                   |        Version:  7.7             
Resolution:                             |       Keywords:                  
        Os:  Unknown/Multiple           |   Architecture:  Unknown/Multiple
   Failure:  GHC rejects valid program  |     Difficulty:  Unknown         
  Testcase:                             |      Blockedby:                  
  Blocking:                             |        Related:                  
----------------------------------------+-----------------------------------
Changes (by Mathnerd314):

  * status:  closed => new
  * type:  bug => feature request
  * resolution:  wontfix =>


Comment:

 Ah, so I am really filing a feature request! I propose an extension which
 changes the grammar to be as follows:
 {{{
 decl    →       funlhs rhs

 funlhs  →       pat { apat }
         |       pat varop pat
         |       ( funlhs ) { apat }

 apat    →       funlhs
         |       var [ @ apat]
         |       ...
 }}}
 I think this introduces a small amount of ambiguity in the grammar (funlhs
 → pat → lpat → apat → funlhs), but it should be easy to transform the
 grammar so as to avoid it.

 Note that your definition for g, although not rejected outright by GHC,
 does produce a warning that "Pattern matches are overlapped." I think such
 a warning would suffice for f as well. There is nothing in the report
 specifying that multiple pattern bindings MUST give an error; instead, it
 is mute on the subject. It does not even specify the semantics of single
 pattern bindings very clearly, as the (implemented but still unaccepted?)
 proposal http://hackage.haskell.org/trac/haskell-
 prime/wiki/SpecifyPatternBindingSemantics shows.

 This grammar allows convenient definitions such as the following (adapted
 from the numbers package)
 {{{
 (x < y, x > y) = (<0) &&& (>0) $ s' (digitsToBits digits) where (CR s') =
 x-y
 }}}
 desugared as follows:
 {{{
 z x y = (<0) &&& (>0) $ s' (digitsToBits digits) where (CR s') = x-y
 x > y = case (z x y) of { (x < y, x > y) -> (x > y) }
 x < y = case (z x y) of { (x < y, x > y) -> (x < y) }
 }}}
 The case expression should perhaps be desugared a bit more so the
 semantics are clear:
 {{{
 case (z x y) of { (a,b) -> let { (x < y) = a; (x > y) = b } in ... }
 }}}
 If you think this is too mind-bending to be useful, I suppose the syntax
 could be restricted a bit; but I find the generality to be rather pretty.

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



More information about the ghc-tickets mailing list