[GHC] #14100: Nested NPlusKPatterns

GHC ghc-devs at haskell.org
Fri Aug 18 12:32:47 UTC 2017


#14100: Nested NPlusKPatterns
-------------------------------------+-------------------------------------
        Reporter:  ralf              |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Old description:

> Nested patterns involving NPlusKPatterns cause a "parse error in
> pattern". Example appended below.
>
> > {-# LANGUAGE NPlusKPatterns #-}
> > {-# LANGUAGE ViewPatterns, PatternSynonyms #-}
>
> > infix 1 :^:
> >
> > data Bush elem = Nil | Bud elem | Bush elem :^: Bush elem
>
> > test ((n + 1) + 1) = n
>
> > pattern DivMod2 ∷ (Integral nat) ⇒ nat → nat → nat
> > pattern DivMod2 n k ← ((`divMod` 2) → (n, k)) where DivMod2 n k =  2 *
> n + k
>
> > braun ∷ Integer → Bush ()
> > braun (0)                = Nil
> > braun (1)                = Bud ()
> > braun (DivMod2 n k + 2)  = braun (n + k + 1) :^: braun (n + 1)

New description:

 Nested patterns involving NPlusKPatterns cause a "parse error in pattern".
 Example appended below.
 {{{
 > {-# LANGUAGE NPlusKPatterns #-}
 > {-# LANGUAGE ViewPatterns, PatternSynonyms #-}

 > infix 1 :^:
 >
 > data Bush elem = Nil | Bud elem | Bush elem :^: Bush elem

 > test ((n + 1) + 1) = n

 > pattern DivMod2 ∷ (Integral nat) ⇒ nat → nat → nat
 > pattern DivMod2 n k ← ((`divMod` 2) → (n, k)) where DivMod2 n k =  2 * n
 + k

 > braun ∷ Integer → Bush ()
 > braun (0)                = Nil
 > braun (1)                = Bud ()
 > braun (DivMod2 n k + 2)  = braun (n + k + 1) :^: braun (n + 1)
 }}}

--

Comment (by simonpj):

 Fair point.

 However, Haskell 98 insists on a variable to the left of the `+`.  Here's
 the [https://www.haskell.org/onlinereport/exps.html Haskell 98 report]:
 look in 3.17.1.

 n+k patterns were removed in later versions of Haskell (Haskell 2010 I
 think) but GHC still supports them.  It think it's unlikely we'll
 elaborate them, however.

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


More information about the ghc-tickets mailing list