我的程序在元组列表中搜索</ strong>我将其写为以下
import List
data BookInfo = Book Int String [String]
deriving(Show)
enter :: Int->String->[String]->BookInfo
enter id name subject=Book id name subject
bookId (Book id _ _ ) = id
index :: BookInfo -> Int
index (Book id name subject) = bookId (Book id name subject)
arrayentering ::BookInfo->[BookInfo]->[BookInfo]
arrayentering (Book id name subject) [] =[(Book id name subject)]
arrayentering (Book _ " " [" "]) [] =[]
arrayentering (Book id name subject) [(Book it namr suject)]=
(Book id name subject):[(Book it name suject)]
toList::[BookInfo]->[Int]
toList [(Book id name subject) ]= map index [ (Book id name subject)]
bubbleSort::(Ord t) => [t]->[t]
bubbleSort[x,y,z,xs]=
if x<y then x : [y,z,xs]
else y : [x,z,xs]
superBubble::(Ord t) => [[t]]->[[t]]
superBubble a=map bubbleSort a
combining::[BookInfo]->[[Int]]
combining [(Book id name subject)]=superBubble [toList [(Book id name subject)]]
并从任何语法错误中清除它但在我尝试输入到combining()
的元组列表后,它会给我发送运行时错误说
Exception:Not Exhaustive pattern in function Main.combining
这是什么意思?
请给我指示。如果可能的话,我想自己解决这个问题。
答案 0 :(得分:3)
函数定义中的模式
combining [(Book id name subject)]=superBubble [toList [(Book id name subject)]]
仅匹配具有一个元素的列表。您在bubbleSort
中遇到了类似的问题,其中
bubbleSort[x,y,z,xs]=
仅匹配具有四个元素和其他地方的列表。
我还没弄明白你打算如何工作,也许是使用变量模式(匹配所有参数)
combining books = superBubble (toList books)
适合吗?
我怀疑
arrayentering ::BookInfo->[BookInfo]->[BookInfo]
arrayentering (Book id name subject) [] =[(Book id name subject)]
arrayentering (Book _ " " [" "]) [] =[]
arrayentering (Book id name subject) [(Book it namr suject)]=
(Book id name subject):[(Book it name suject)]
应该是
arrayentering book bookList
| empty book = bookList
| otherwise = book : bookList
where
empty (Book _ name subject) = all isSpace name && all (all isSpace) subject
(empty
可能有误)。
toList
应该只是map index
。