Advertisement
Guest User

Untitled

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