2016-03-04 73 views
0

我有一些处理列表(代表矩阵)的代码。每个单元格是NB。我想为每行代表矩阵的数量为N。例如:[[B,B,N],[N,N,N]][1,3]表示。错误:Haskell中的非穷举模式

这里是我的代码:

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) 

的问题是在功能projH,我显然缺少一个模式,但我做处理与[[],...]testCase功能和[[]]案件的情况。我不知道为什么它抛出我这个错误:

*Main> projH g0 
[1,2,6,3,3,3*** Exception: devoir.hs:(17,1)-(18,39): Non-exhaustive patterns in function projH 

回答

4
projH [] = [] 

,而不是你

projH [[]] = [] 

当你写的情况下,由其他语句通过分配x = []xg = []

已经处理
+0

非常感谢,很明显... – pioupiou1211