I have a function that finds empty cells in a chess game I am making, and I want to replace one of my pieces into that empty spot that I found. I have a function for findCells, so I have a code something like this
movePawnBack :: GameState -> Player -> [[Cell]]
movePawnBack g p = if p == Black then BP = findCells g E else WP = findCells g E
findCells :: GameState -> Cell -> [(Int, Int)]
findCells b c = [(x, y) | x <- [0..4], y <-[0..4], getFromBoard (theBoard b) (x, y) == c]
However, it gives me an error that I don't have an else cause and if I do something like this BP ==... then I just return a boolean type which is not what I want. Is there an easier way to do this?
movePawnBack.BP = findCells g Ethis is invalid, there is no assignment or mutation or whatever you are trying to do there. Secondly what isE,WP,BPand where did they come from?findCells g E, check if the result isBP, and if it's not, throw an error."BPdoesn't look at all like a[(Int, Int)], which is the kind of thingfindCellsreturns. But it's very unclear what it is intended to mean!