[GHC] #14112: bang patterns on pattern synonyms? (left vs right hand sides)
GHC
ghc-devs at haskell.org
Mon Aug 28 18:00:50 UTC 2017
#14112: bang patterns on pattern synonyms? (left vs right hand sides)
-------------------------------------+-------------------------------------
Reporter: carter | Owner: RyanGlScott
Type: bug | Status: new
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):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by RyanGlScott):
They might be ignored for data constructors, yes. But what about pattern
synonyms? For instance, we have that:
{{{
λ> pattern Id a = a
λ> let f (Id _) = "foo"
λ> f undefined
"foo"
λ> let g !(Id _) = "bar"
λ> g undefined
"*** Exception: Prelude.undefined
CallStack (from HasCallStack):
error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
undefined, called at <interactive>:19:3 in interactive:Ghci9
}}}
That is to say, bang patterns aren't no-ops for //every// conlike, as they
matter in the presence of pattern synonyms. This awkwardly melds with
implicitly bidirectional pattern synonyms, since if you define this:
{{{
λ> pattern Foo a = Just !(Id a)
λ> case Foo undefined of Just _ -> "wat"
"wat"
λ> case Just undefined of Foo _ -> "wat"
"*** Exception: Prelude.undefined
CallStack (from HasCallStack):
error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
undefined, called at <interactive>:22:11 in interactive:Ghci11
}}}
Notice that the bang pattern doesn't kick in when `Foo` is used as an
expression, only as a pattern. In order to make a `Foo` expression strict
as a pattern, you'd have to dig underneath the `Id` pattern synonym to
figure out whether //its// bindings are strict or not.
All of this sounds terribly fiddly in contrast to option (A), which is
simple to describe, implement, and even gives nice error messages.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14112#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list