I read this blog post on how to create a custom Prelude library. The library can be found here. One of the things it does is prohibit String
. It also defines a function for automatic string conversions (here). I have enabled OverloadedStrings
in the cabal file.
Before using this library I had:
data Point = Point Int Int
instance Show Point where
show (Point x y) = "(" ++ show x ++ ", " ++ show y ++ ")"
After using the library it says: "show' is not a (visible) method of class
Show'"
So I resorted to create a custom function to show the data type:
showPoint :: Point -> LText
showPoint (Point x y) = toS ("(" ++ show x ++ ", " ++ show y ++ ")")
The compiler is saying that the use of toS, "(", show
is ambiguous, but I don't understand why. Do I have to do something like what is proposed here?
Edit:
Had to disable OverloadedStrings and change the code to the following:
showPoint :: Point -> LText
showPoint (Point x y) = toS "(" <> show x <> toS ", " <> show y <> toS ")"
Wondering if it is possible to do the same without disabling OverloadedStrings so I don't have to use toS
for every String
.