Bang pattern doesn't work on a newtype constructor
According to the documentation, f0 and f1 in the following program should have the identical semantics:
{-# LANGUAGE BangPatterns #-}
module Main where
newtype N = N Int
f0 :: N -> Int
f0 n = case n of
!(N _) -> 0
_ -> 1
f1 :: N -> Int
f1 n = n `seq` case n of
N _ -> 0
_ -> 1
main = do
print $ f0 undefined
print $ f1 undefined
However, ghc only compiles f1 into a strict function:
% ./bang-newtype
0
bang-newtype: Prelude.undefined
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.8.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |