
On Mon, 2009-10-05 at 10:42 +0100, Sittampalam, Ganesh wrote:
Bas van Dijk wrote:
Hello,
It would be really nice to use OverloadedStrings when constructing a ShowS, for example in a definition of showsPrec in an instance for Show.
The patch attached in the ticket[3544] adds the necessary instance to base/GHC/Show.lhs:
instance IsString ShowS where fromString = showString
Note that this does require TypeSynonymInstances.
-1 : I don't think it's appropriate to use a type synonym instance in a standard library.
Strictly speaking it's not the type synonym that is worrying, it's the need for flexible instances which then leads on to needing overlapping and incoherent instances. http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extension...
A concrete example of the problems this would cause is that it would interfere with any generic function instance for IsString, e.g.
instance IsString b => IsString (a -> b) where fromString = const . fromString
Right, then uses of fromString would require -XOverlappingInstances and possibly -XIncoherentInstances. This needs -XOverlappingInstances foo :: String -> String foo = fromString "blah" This needs -XOverlappingInstances -XIncoherentInstances foo :: a -> String foo = fromString "blah"
I am not suggesting that such an instance is generally useful, but people who wanted to use it in their own private code would be obstructed from doing so by an instance for (String -> String).
Right. It makes me nervous too. I think what this show us is that ShowS should have been a newtype. Duncan