我不确定我没有处理什么。假设我有一个函数,它将整数转换为字符串。调用它converter
。
现在,要将位置整数转换为字符串,我只需调用converter
. 要将负整数转换为字符串,我附加-
到converter
调用。
这是我的代码:
converter :: Integer -> String
converter x
| x == 0 = "0"
| x == 1 = "1"
| x == 2 = "2"
| x == 3 = "3"
| x == 4 = "4"
| x == 5 = "5"
| x == 6 = "6"
| x == 7 = "7"
| x == 8 = "8"
| x == 9 = "9"
| x > 9 = z
where
(a, b) = divMod x 10
z = (converter a) ++ (converter b)
negOrPosConverter :: NegOrPosInteger -> String
negOrPosConverter (ActualInt x)
| x >= 0 = converter x
| x < 0 = "-" ++ (converter x)
当我运行代码并尝试时negOrPosConverter (ActualInt (-200))
,出现此错误:
"-*** Exception: theConverter.hs:(19,1)-(27,32): Non-exhaustive patterns in function converter
知道为什么吗?