【发布时间】:2020-10-20 01:19:44
【问题描述】:
我收到以下错误:
没有因使用“打印”而产生 (Show Exp) 的实例
在表达式中:打印 ti1
在“it”的等式中:it = print ti1
当我
ghci>ti1 = Add (Lit 8) (Neg (Add (Lit 1) (Lit 2)))
ghci>print ti1
我的整个代码是:
data Exp = Lit Int
| Neg Exp
| Add Exp Exp
view:: Exp -> String
view (Lit n) = show n
view (Neg e) = "(-" ++ view e ++ ")"
view (Add e1 e2) = "(" ++ view e1 ++ " + " ++ view e2 ++ ")"
如何打印这个字符串?
【问题讨论】:
标签: haskell