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
任何幫助解決這個問題都是值得歡迎的!