[GHC] #9206: OverloadedString breaks show?

#9206: OverloadedString breaks show? ------------------------------------+------------------------------------- Reporter: j80JjBjVNRMajmA | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- 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" }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9206 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9206: OverloadedStrings breaks show? -------------------------------------+------------------------------------ Reporter: j80JjBjVNRMajmA | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9206#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9206: OverloadedStrings breaks show? -------------------------------------+------------------------------------ Reporter: j80JjBjVNRMajmA | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): This behaviour is mostly documented in the [http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class- extensions.html#overloaded-strings overloaded strings section of the user manual], although there is an important omission: with `-XOverloadedStrings`, the default types (if none are specified by the user) are `Integer, Double, String`, not just `Integer, Double`. Reminder: `fromString :: IsString a => String -> a`, exported by `GHC.Exts`. So * Without `-XOverloadedStrings`, `test.hs` is rightly rejected. * With `-XOverloadedStrings`, defaulting kicks into play and chooses the first type from `Integer, Double, String` that satisfies `(Show a0, IsString a0)`. The only satisfying type is `String` so that is chosen. * In `test2.hs`, `Double` is made an instance of `IsString`, so that is picked first, before `String`. So it all looks right except that the user manual is deficient. I'll fix that. Of course, you could argue that the specification is wrong. If you want to do that, we should go back to the original discussion threads on overloaded strings. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9206#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9206: OverloadedStrings breaks show? -------------------------------------+------------------------------------ Reporter: j80JjBjVNRMajmA | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by j80JjBjVNRMajmA): * status: new => closed * resolution: => invalid Comment: Now everything makes sense. I never heard about the `defaulting` stuff (seems to be an easily overlooked detail?), and thus am in no position to argue about its interplay with OverloadedString ... (for now). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9206#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9206: OverloadedStrings breaks show?
-------------------------------------+------------------------------------
Reporter: j80JjBjVNRMajmA | Owner:
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Resolution: invalid | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones
participants (1)
-
GHC