I've a hard time understanding a Chess Knight problem concerning function composition. The exercise is a generator/filter/selector chain with a given wrapper function (knightProblem) which glues everything together.
It is unclear to me how the function kGenerator as the first piece in the chain should handle multiple parameters:
-- Chess Knight Problem: Generate all Knight moves of length NrMoves
-- that end at the target position
knightProblem :: StartPos -> NrMoves -> TargetPos -> [Moves]
knightProblem = kSelector . kFilter . kGenerator
-- kGenerator: needs StartPos, NrMoves, generates all sequences of length NrMoves
-- kFilter: remove all moves which contain invalid positions
-- kSelector: keep all moves which terminate at TargetPos
kGenerator :: ???
???
I'm looking for hints on how to handle this kind of problems.
Best regards.
Try writing down type signatures for the other functions.
So it looks like
kGeneratorshould providekFilterwith[Moves]:Think about what
[Moves]are; this is likely something like[[Position]], a list of position lists representing the chain of moves.An obvious way to generate moves from a given position would be doing the 8 possible moves, and then recursively generating more moves from each of these positions.
Hopefully this will help you get through your assignment :)