0
我有一個Evol類,並希望將distanceMatrix的一個實例應用到我的類型MolSeq的列表中。函數molseqDistMat按照需要工作,但我無法理解嘗試運行distanceMatrix [Molseq]時得到的錯誤。我明白錯誤是什麼,但我找不到例外。這是錯誤。Haskell函數中的非窮舉模式
*F2> distanceMatrix l
*** Exception: lab2.hs:79:3-43: Non-exhaustive patterns in function
distanceMatrix
這是代碼。
class Evol a where
distanceMatrix :: [a] -> [(String, String, Double)]
instance Evol MolSeq where
distanceMatrix [a] = molseqDistMat [a] [] -- <- Line 79
molseqDistMat :: [MolSeq] -> [(String, String, Double)] -> [(String,
String, Double)]
molseqDistMat todo res
| null (tail todo) = res
| otherwise = molseqDistMat (tail todo) (res++(doRow (head todo) (tail
todo) []))
doRow :: MolSeq -> [MolSeq] -> [(String, String, Double)] -> [(String,
String, Double)]
doRow mol rest result
| null rest = reverse result
| otherwise = doRow mol (tail rest) ((name mol, name (head rest),
distance mol (head rest)):result)
使用'-Wall'啓用警告:您將在編譯時發現此問題,而且GHC甚至會提供一個未在您的定義中涵蓋的列表示例。 – chi
感謝您的提示! –