我有一个类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)
您可能想要:
distanceMatrix xs = molseqDistMat xs [] -- <- Line 79
[a]
是一种与一个元素的列表匹配的模式。