我有一个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)
答案 0 :(得分:3)
你可能想要:
distanceMatrix xs = molseqDistMat xs [] -- <- Line 79
[a]
是一个匹配一个元素列表的模式。