我有一个 Evol 类,并希望将 distanceMatrix 的实例应用于我的 MolSeq 类型的列表。函数 molseqDistMat 可以按需要工作,但我无法理解尝试运行 distanceMatrix [Molseq] 时遇到的错误。我了解错误的含义,但找不到异常。这是错误。
*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)