2013-04-17 229 views
1

遇到了麻煩,從一個輔助功能輸出到我的函數的輸出相匹配,我用下面的代碼我:Haskell-類型匹配

getSemiDiag :: [[Maybe Player]] -> Int -> Int -> [Maybe Player] 
getSemiDiag [] _ _ = [] 
getSemiDiag (x:xs) start size = if start > (size -1) 
          then [] 
          else (x !! start) : (getSemiDiag xs (start+1) size) 



semiRight :: [[Maybe Player]] -> Int -> Int -> [[Maybe Player]] 
semiRight [] _ _ = [] 
semiRight (x:xs) start size = if start > (size -1) 
          then [] 
          else (getSemiDiag x start size) : (semiRight xs (start+1) size) 

功能semiRight不會,儘管我盡了最大努力匹配。有什麼想法嗎?

+3

我不知道你想達到什麼,但你傳遞一個'[也許播放器]''到哪裏getSemiDiag'一個期望了' [[也許玩家]]'。你的意思是讓'getSemiDiag(x:xs)開始大小:semiRight xs(start + 1)size'? –

+3

'然後[]'應該可以'然後[[]]' – Wes

+0

謝謝! – lopezrican304

回答

1

僅從類型來看,x被匹配到具有類型的[Maybe Player]一個元件,

你應該明顯通過[X]但不x到getSemiDiag。此外,一些括號是多餘的。

semiRight :: [[Maybe Player]] -> Int -> Int -> [[Maybe Player]] 
semiRight [] _ _ = [] 
semiRight (x:xs) start size = if start > (size -1) 
          then [] 
          else getSemiDiag [x] start size : semiRight xs (start+1) size 

爲什麼不直接使用zipWith