2016-03-04 70 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