So I'm writing a game in Haskell, and I'm expressing a player's turn as a series of state-altering functions that correlate to various turn phases. Originally, this looks something like:
let game' = phase1 game
game'' = phase2 game'
-- etc.
Prime candidate for State monadosity, right? This leads to the more elegant:
do
phase1
phase2
-- etc.
However, then it seems like I have to change phase1
, phase2
, et al to begin with a boilerplate "State getting" step:
phase1 = get >>= \game -> -- ...
I'm hoping there's a way to abstract this out, so I can avoid boilerplate on both the caller and the callee. I'm just too new to know what this way is (this is my first real Haskell project). Any advice?