I have some code that deals with a list of lists (that represents a matrix). Each cell is an N or a B. I want to represent the matrix with the number of Ns for each line. For example: [[B,B,N],[N,N,N]] is represented by [1,3].
Here's my code:
data Case = B|N deriving (Show, Eq)
type Grille =[[Case]]
g0,g1 :: Grille
g0 = [[B,B,B,B,B,B,N],[B,B,N,B,N,B,B],[N,B,N,N,N,N,N],[B,B,B,N,N,B,N],[N,N,N,B,B,B,B],[B,B,B,N,N,B,N]]
g1 = [[B,B,B,B,B,B,B],[B,B,N,N,N,B,B],[B,B,N,N,N,N,N],[B,B,B,N,N,N,N],[N,N,N,B,B,B,B],[B,B,B,N,B,B,B]]
projH :: Grille -> [Int]
projH [[]] = []
projH (x:xg) = testCase(x) ++ projH(xg)
testCase :: [Case] -> [Int]dans une ligne
testCase [] = [0]
testCase (x:xs)
| x == N = [head(testCase(xs))+1]
| otherwise = testCase(xs)
The problem is in the function projH, I'm obviously missing a pattern, but I do handle the case with [[],...] with the testCase function and the [[]] case. I don't know why it throws me this error:
*Main> projH g0
[1,2,6,3,3,3*** Exception: devoir.hs:(17,1)-(18,39): Non-exhaustive patterns in function projH
Aucun commentaire:
Enregistrer un commentaire