I\'m trying to build a recursive function that replaces the CellType by the Cell. Just like this:
> editBoard [((2,2),Mine),((2,3),Mine),((3,2),Mine)]((2, 4), F
The signature of your function says you are returning a Board
, but the otherwise
clause will return a list:
editBoard :: Board -> (Cell, CellType) -> Board
editBoard (Board ((x, y):xs)) (a, b)
| x == a = (Board ((x, b) : xs))
| otherwise = ((x, y) : editBoard (Board xs) (a, b))
I think however you make things too complicated. It might be better to make a helper function that works with a list of (Cell, CellType)
objects, and returns such list, and let the editBoard
wrap and unwrap the content:
editBoard :: Board -> (Cell, CellType) -> Board
editBoard (Board bs) xy@(x0, y0) = Board (go bs)
where go :: [(Cell, CellType)] -> [(Cell, CellType)]
go … = …
I leave implementing go
as an exercise.