typeclass polymorphism defeats bang patterns
I think the following program should crash, but it doesn't:
{-# LANGUAGE BangPatterns #-}
main = let n :: Num a => a; !n = undefined in return ()
Interestingly, my attempt to translate this out of BangPatterns into standard Haskell according to the translation on the wiki page led to a compile-time error:
main = let n :: Num a => a; x@n = undefined in x `seq` return ()
Produces the error:
test.hs:1:12: error:
• Overloaded signature conflicts with monomorphism restriction
n :: forall a. Num a => a
• In the expression:
let
n :: Num a => a
x@n = undefined
in x `seq` return ()
In an equation for ‘main’:
main
= let
n :: Num a => a
x@n = undefined
in x `seq` return ()
|
1 | main = let n :: Num a => a; x@n = undefined in x `seq` return ()
| ^^^^^^^^^^^^^^^
Even giving x its own explicitly polymorphic type signature -- what I thought was the standard way to prevent the monomorphism restriction from being a problem -- doesn't help. I'm uncertain what to make of that, but it certainly seems related: earlier versions of the compiler both do not give that error and do produce a crashing program, as I expected.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.2.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |