Non-exhaustive pattern in function in Haskell

151 Views Asked by At

I have a class Evol and want an instance of distanceMatrix to be applied on a list of my type MolSeq. The function molseqDistMat works as desired, but I cant understand the error I get when trying to run distanceMatrix [Molseq]. I understand what the error says but I can't find the exception. This is the error.

*F2> distanceMatrix l
*** Exception: lab2.hs:79:3-43: Non-exhaustive patterns in function 
distanceMatrix

This is the code.

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)
1

There are 1 best solutions below

0
On BEST ANSWER

You probably want:

distanceMatrix xs = molseqDistMat xs [] -- <- Line 79

[a] is a pattern that matches a list of exactly one element.