|
|
|
|
|
by tel
4711 days ago
|
|
That can kind of be done using `Context`s, but those are really just implementation details and should rarely be used. Broadly, you wouldn't want to do that because it implies mutation. There's not much value in `player1.location.x %~ (+10)` because it can't modify player1... just return a modified (player1'new). Of course, stateful mutation is just a monadic effect, so you can wrap it up into a State monad, which Lens already has shortcuts for do
location.x += 10
location.y += 10
which has type like `MonadState ThingWithLocation m => m ()` and we can then apply it to whatever `player` we want as a pure function. |
|