OverloadedStrings breaks show?
The file test.hs
contains
import GHC.Exts
main = putStrLn $ show (fromString "01")
and results in:
ghc -XNoOverloadedStrings test.hs
overloadedString.hs:4:20:
No instance for (Show a0) arising from a use of ‘show’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
instance Show Double -- Defined in ‘GHC.Float’
instance Show Float -- Defined in ‘GHC.Float’
instance (Integral a, Show a) => Show (GHC.Real.Ratio a)
-- Defined in ‘GHC.Real’
...plus 44 others
In the second argument of ‘($)’, namely ‘show (fromString "01")’
In the expression: putStrLn $ show (fromString "01")
In an equation for ‘main’: main = putStrLn $ show (fromString "01")
overloadedString.hs:4:26:
No instance for (IsString a0) arising from a use of ‘fromString’
The type variable ‘a0’ is ambiguous
Note: there is a potential instance available:
instance IsString [Char] -- Defined in ‘Data.String’
In the first argument of ‘show’, namely ‘(fromString "01")’
In the second argument of ‘($)’, namely ‘show (fromString "01")’
In the expression: putStrLn $ show (fromString "01")
OverloadedStrings breaks things (by making them magically work, which is probably why nobody complained?)
ghc -XOverloadedStrings -e main test.hs
"01"
and another test2.hs
:
import GHC.Exts
instance IsString Double where
fromString = read
main = putStrLn $ show (fromString "01")
ghc -XOverloadedStrings -e main test2.hs
"1.0"
Trac metadata
Trac field | Value |
---|---|
Version | 7.8.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |