这是我正在处理的代码的简化版本
data ArithExp = Con Int
| Add ArithExp ArithExp
instance Show ArithExp where
show (Con i) = show i
show (Add e1 e2) = show "( " ++ show e1 ++ " + " ++ show e2 ++ " )"
所以,如果我运行命令
Add (Con 6) (Con 0)
我想要的输出是:
( 6 + 0 )
但上面的代码打印:
"( "6 + 0 )
据我所知,show 函数将第一个字符串中的引号打印为字符,然后在随后的连接中正确使用它们。这种行为对我来说似乎真的很不一致。任何有助于我获得正确输出的见解将不胜感激。提前致谢!