[GHC] #14112: bang patterns on pattern synonyms? (left vs right hand sides)

GHC ghc-devs at haskell.org
Tue Aug 29 01:29:54 UTC 2017


#14112: bang patterns on pattern synonyms? (left vs right hand sides)
-------------------------------------+-------------------------------------
        Reporter:  carter            |                Owner:  RyanGlScott
            Type:  bug               |               Status:  patch
        Priority:  normal            |            Milestone:  8.4.1
       Component:  Compiler          |              Version:  8.2.1
      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):  Phab:D3896
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):

 * status:  new => patch
 * differential:   => Phab:D3896


Comment:

 I've implemented (A) in Phab:D3896.

 Replying to [comment:10 carter]:
 > so what i'm sensing is the point that
 >
 > normal / "strict" data types are only strict on construction, but lazy
 on matching (except perhaps when dealing with unpacked/unboxed style
 internal tricks eg mapping Int to Int# etc).
 >
 > In contrast, we have here a way that can express lazy construction and
 strict matching?
 >
 > am i missing something?

 I'd summarize the point by saying that if you were to hypothetically allow
 an implicitly bidirectional pattern synonym with a bang pattern in the
 RHS, you'd want both the pattern and the builder expression to be strict.
 However, in practice GHC was making the pattern strict, but not the
 builder. We pondered whether it would be possible to desugar a builder
 that figured out the right strictness, but this turns out to be an awkward
 thing to do in the presence of other pattern synonyms in the RHS.

 It's much easier to simply disallow bang patterns in the RHS altogether,
 since this avoids the need to explain away a special syntactic rule that
 only applies for expressions in implicitly bidirectional pattern synonyms.
 (In Phab:D3896, I've tailored the error message so that if you do try
 typing something like `data StrictJust a = Just !a`, it recommends using
 an explicitly bidirectional pattern synonym instead.)

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


More information about the ghc-tickets mailing list