我无法从辅助函数获取输出以匹配我正在使用以下代码的函数输出:

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还是无法匹配。 有什么想法吗?

===============>>#1 票数: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

semiRight players start size = zipWith (\p i -> [p !! i]) players [start .. size]

  ask by lopezrican304 translate from so

未解决问题?本站智能推荐: