首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >读取Haskell中的值和列表

读取Haskell中的值和列表
EN

Stack Overflow用户
提问于 2018-06-08 02:28:48
回答 2查看 276关注 0票数 -1

在将这个问题标记为重复之前,我已经阅读了这个主题: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:
        ([]:_:_)
        ([_]:_)
        ([_, _]:_)
        ((_:_:_:_:_):_)

我的问题是如何创造所有这些条件。

如果有人能帮我创造那些可能决定“停止条件”的条件,我将不胜感激。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50747937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档