所以在一个文件中我有
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
Run Code Online (Sandbox Code Playgroud)
在另一个名为 MyShow.hs 的文件中我有
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances …Run Code Online (Sandbox Code Playgroud)