2
我在Haskell中编写了一个程序,它可以很好地打印表格并对其执行基本查询。下面的函数是打印表格中的代码的一个片段:功能非穷举模式
printTable :: Table -> [String]
printTable [email protected](header:rows) = [addLine] ++ addHeader ++ [addLine] ++ addRows rows ++ [addLine]
where widthList = columnWidths table
makeTupleList [] = []
makeTupleList (x:xs) = zip widthList x : makeTupleList (xs)
addRows line = map printRow (makeTupleList line)
addLine = printLine widthList
addHeader = addRows [(map.map) toUpper header]
注:Table == [[String]]
调用带“unlines”功能该功能后,被印刷在表。
如果我测试这个函数,给它一个[[String]]
参数,它工作正常。但是,如果我测试我的“主”这个代码的功能,我得到的错误:
Non-exhaustive patterns in function printTable
唯一的区别是,在我的主要代码,该程序的用户可以给一个文本文件作为输入:
main :: IO()
main = interact (lines >>> exercise >>> unlines)
exercise :: [String] -> [String]
exercise = parseTable >>> select "gender" "male"
>>> project ["last", "first", "salary"] >>> printTable
任何帮助解决这个问题都是值得欢迎的!