'Haskell Show bug?

So in one file I have

import Data.String
import MyShow

data Tree a b = Leaf a | Branch b (Tree a b) (Tree a b)

instance (Show a, Show b) => Show (Tree a b) where
   show (Branch n t1 t2) = "(" ++ myshow t1 ++ myshow n ++ myshow t2 ++ ")"
   show (Leaf l) = myshow l

newtype MyString = MyString String

instance Show MyString where
    show (MyString s) = s

and in another file called MyShow.hs I have

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
module MyShow where

class MyShow a where
    myshow :: a -> String

instance {-# OVERLAPPING #-} MyShow String where
    myshow s = s
    
instance Show a => MyShow a where
    myshow = show

When I load the first file in ghci, (Branch "+" (Leaf 1) (Leaf 2) shows (1"+"2) and when I try "(" ++ myshow (Leaf 1) ++ myshow "+" ++ myshow (Leaf 2) ++ ")", that shows (1+2), which is what I want.

What is the reason for this discrepancy and how do I fix it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source