【发布时间】:2012-03-08 02:51:33
【问题描述】:
我声明了一个新的内存类型,然后使用一个函数来更新它。当我向列表中添加值时,程序编译并正常工作,但如果我的列表为空,我会收到错误:
*** Exception: Non-exhaustive patterns in function update
这是我的代码,如果你能帮助我:
type Name = [Char]
type Memory = [(Name, Integer)]
update :: Name -> Integer -> Memory -> Memory
update n x (h:t)
| fst h == n = (n, x) : t
| h : t == [] = [(n, x)]
| otherwise = h : update n x t
【问题讨论】:
标签: haskell