I am trying to accomplish the following:
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)]
Specifically, I'm trying to run a function, take the result [[int]], then map another function onto that result. Which haskell appearantly abhors, and I need to use some combination of "lambda functions" and other wizardry I cant read or comprehend at all to get this chugging along.
Is there any simple way to do this that wont require a 7 month course in mathematical function syntax?
As mentioned above, the result, board, is [[int]], and sequence is simply [int].
The errors it produces are
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.
Boardis a synonym forSequence, your types don't agree.getBox s y x = [ (trimBoard c x) | c <- (trimBoard s y)]is rejected by ghc with a flood of errors which I dont understand. I THINK they are complaining that x is supposed to be an int, but has instead somehow become an [int], but I am unsure about that.BoardandSequencetypes. This is for future readers and searchability.cin expressionc <- (trimBoard s y)has type[Int], but the first argument oftrimBoardneed typeBoard, i.e.[[Int]], it is not match. In addition,getBoxfinally has type[Board]not [Sequence]`.[ ... | c <- trimBoard... ]means for each elementcof the listtrimBoard. Sochas the element type of whatever list you are binding it to.