Haskell- Type matching -
i having trouble getting output helper function match output of function using code below:
getsemidiag :: [[maybe player]] -> int -> int -> [maybe player] getsemidiag [] _ _ = [] getsemidiag (x:xs) start size = if start > (size -1) [] 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) [] else (getsemidiag x start size) : (semiright xs (start+1) size)
the function semiright won't match despite best efforts. thoughts?
judging type, x
matched element has type of [maybe player]
,
you should pass [x] not x getsemidiag. moreover, brackets redundant.
semiright :: [[maybe player]] -> int -> int -> [[maybe player]] semiright [] _ _ = [] semiright (x:xs) start size = if start > (size -1) [] else getsemidiag [x] start size : semiright xs (start+1) size
why not use zipwith
semiright players start size = zipwith (\p -> [p !! i]) players [start .. size]
Comments
Post a Comment