我正在尝试完成以下任务:
slice :: Int -> Int -> [a] -> [a]
slice from to xs = take (to - from + 1) (drop from xs)
trimBoard :: Board -> Int -> Board
trimBoard s y = slice ((y*3)) (((y+1)*3)-1) s
getBox :: Board -> Int -> Int -> [Sequence]
getBox s y x = [ (trimBoard c x) | c <- (trimBoard s y)]
具体来说,我正在尝试运行一个函数,获取结果[[int]]
,然后将另一个函数映射到该结果。哪个haskell似乎很令人讨厌,我需要使用“ lambda函数”和我完全无法阅读或理解的其他向导的某种组合来实现这一点。
有没有简单的方法可以不需要7个月的数学函数语法课程?
如上所述,结果board是[[int]],而序列只是[int]。
它产生的错误是
sudoku.hs:139:19: error:
• Couldn't match type ‘[Int]’ with ‘Int’
Expected type: Sequence
actual type: Board
• In the expression: (trimBoard c x)
In the expression: [(trimBoard c x) | c <- (trimBoard s y)]
In an equation for ‘getBox’:
getBox s y x = [(trimBoard c x) | c <- (trimBoard s y)]
sudoku.hs:139:29: error:
• Couldn't match type ‘Int’ with ‘[Int]’
Expected type: Board
actual type: Sequence
• In the first argument of ‘trimBoard’,namely ‘c’
In the expression: (trimBoard c x)
In the expression: [(trimBoard c x) | c <- (trimBoard s y)] Failed,modules loaded: none.