问题是你覆盖了Show的默认实现,但是依赖于Read的默认实现,它需要"One"或"Zero",而不是"1"或"0".
解决方案是编写自己的Read实现(你可以保留Eq和Ord):
import qualified Data.ByteString.Char8 as BSC import qualified Data.ByteString as BS import qualified Data.Map as Map data Bit = One | Zero deriving (Eq,Ord) instance Show Bit where show One = "1" show Zero = "0" instance Read Bit where readsPrec _ ('1':xs) = [(One, xs)] readsPrec _ ('0':xs) = [(Zero, xs)] readsPrec _ _ = [] type Code = Map.Map Char [Bit] writeCode :: FilePath -> Code -> IO () writeCode fp tr = BS.writeFile ("code_" ++ fp) (BSC.pack (show tr)) readCode :: FilePath -> IO Code readCode f = do s <- BS.readFile ("code_" ++ f) let s' = BSC.unpack s return (read s' :: Code)