Recently I started to learn Haskell. I did this by making exercises on the Internet. The problem of making these exercises is that I never know if I solved it the correct way. I currently wrote a function which I think looks really ugly, but I don't know how to improve it. I hope that someone could give me some tips to improve it.
In this exercise I need to make a Tic-Tac-Toe game.
The question of the function I wrote is as follows:
Exercise 8. Write a function
moves :: Player -> Board -> [Board]
that, given the current player and the current state of the board, returns all possible moves that player can make expressed as a list of resulting boards. (For now, you should continue making moves, even if one of the players has already won.)
I wrote the following code:
moves :: Player -> Board -> [Board]
moves p ((a,b,c),(d,e,f), (g,h,i)) = (moves' a (((symbol p),b,c), (d,e,f), (g,h,i))) ++
(moves' b ((a,(symbol p),c), (d,e,f), (g,h,i))) ++
(moves' c ((a,b,(symbol p)), (d,e,f), (g,h,i))) ++
(moves' d ((a,b,c), ((symbol p),e,f), (g,h,i))) ++
(moves' e ((a,b,c), (d,(symbol p),f), (g,h,i))) ++
(moves' f ((a,b,c), (d,e,(symbol p)), (g,h,i))) ++
(moves' g ((a,b,c), (d,e,f), ((symbol p),h,i))) ++
(moves' h ((a,b,c), (d,e,f), (g,(symbol p),i))) ++
(moves' i ((a,b,c), (d,e,f), (g,h,(symbol p))))
moves' :: Field -> Board -> [Board]
moves' c m = if c == B then [m] else []
Is there a way to improve my code?