在将这个问题标记为重复之前,我已经阅读了这个主题:Haskell read Integer and list of lists from file,解决方案没有解决我的问题。
我正在尝试读取包含此结构的File中的内容:
String, String, [(Int, Int, Int)]
该文件如下所示:
Name1 22/05/2018 [(1, 5, 10), (2, 5, 5), (3, 10, 40)]
Name2 23/05/2018 [(1, 10, 10), (2, 15, 5), (3, 50, 40),(4,20,5)]
Name3 22/05/2018 [(4, 2, 1), (5, 2, 2), (6, 50, 3), (1,2,3)]
Name4 23/05/2018 [(1, 3, 10), (2, 1, 5), (3, 2, 40), (6,20,20)]
在Haskell中,我创建了这个函数来读取文件的内容,并将该内容“转换”为我的自定义类型。
rlist :: String -> [(Int, Int, Int)]
rlist = read
loadPurchases :: IO [(String, String, [(Int, Int, Int)])]
loadPurchases = do s <- readFile "tes.txt"
return (glpurch (map words (lines s)))
glpurch :: [[String]] -> [(String, String, [(Int, Int, Int)])]
glpurch [] = []
gplpurch ([name, dt, c]:r) = (name, dt, (rlist c)) : gplpurch r
但是当我尝试执行"loadPurchases“函数时,我得到这样的错误:函数glpurch中的非穷举模式。
使用:set -Wall,我收到了以下帮助消息:
<interactive>:6:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for `glpurch':
Patterns not matched:
([]:_:_)
([_]:_)
([_, _]:_)
((_:_:_:_:_):_)
我的问题是如何创造所有这些条件。
如果有人能帮我创造那些可能决定“停止条件”的条件,我将不胜感激。
https://stackoverflow.com/questions/50747937
复制相似问题