Bang patterns don't work as the specification says
|Reported by:||dolio||Owned by:|
|Type of failure:||Incorrect result at runtime||Test Case:||deSugar/should_run/T8952|
|Related Tickets:||Differential Revisions:|
In investigating the behavior of bang patterns for an implementation of my own, I came across a discrepancy between the specification and GHC's implementation. Here is an example:
case Nothing of !(~(Just x)) -> 5 Nothing -> 12
This evaluates to 12. In other words, !(~p) is equivalent to p. However, the bang patterns description says that this should be equivalent to:
Nothing `seq` case Nothing of ~(Just x) -> 5 Nothing -> 12
which evaluates to 5. So, one of either the description or the implementation must be incorrect. In fact, GHC is even a bit confused, as it issues a warning about overlapping patterns for the bang pattern case statement, even though the successful branch is the 'unreachable' one.
The description makes more sense to me, but I'm not terribly invested in the behavior of this; it is admittedly a pretty obscure corner case.
Change History (4)
comment:3 Changed 13 months ago by simonpj
- Status changed from new to merge
- Test Case set to deSugar/should_run/T8952