Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data TurnPhase = Phase1 | Phase2 deriving Show
- data GamePhase = GamePhase { _playerTurn :: Int
- , _turnPhase :: TurnPhase
- } deriving Show
- makeLenses ''GamePhase
- processEndPhase :: Game -> Game
- processEndPhase game = game
- where
- update gamePhase =
- case gamePhase ^. turnPhase of Phase1 -> gamePhase & turnPhase .~ Phase2
- -- Phase2 -> ...Here I want to both reset _turnPhase to Phase1 and increment _playerTurn
- -- Obviously, I could just return a whole new structure, like GamePhase { _playerTurn = oldTurn + 1, _turnPhase = Phase1 }.
- -- But I was hoping lenses would provide me with a concise, inline way of doing the same thing, especially because
- -- my data structures are probably going to get a lot more complicated than this.
- -- Also, I'd like to avoid using State monads unless that's absolutely what's called for here. I don't totally understand them.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement