0
我聲明瞭一種新的內存類型,然後使用函數來更新它。該程序編譯和工作正常,當我將值添加到列表中,但如果我的列表爲空,我會收到錯誤「函數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):[]
|(fst t==x) = h:(n,t)
|(t==[]) = h:(n,x):[]
|otherwise = h:update n x t
還需要添加到第二檢查n ==可FST^h – apoellitsi 2012-03-08 03:56:18