I'm trying to write a simple Terminal game in Haskell
I have a function:
moveDirection :: Direction -> Position -> Position
which is supposed to move a player. A player looks like this:
data Player = Player String Position Hp
So I want to apply the moveDirection
function to Player
. I could easily do this writing a lift function (I don't know how to call this type of function otherwise):
movePlayer :: (Position -> Position) -> Player -> Player
But I already see myself doing this quite a lot of times, every time I want to act on some part of a data structure. Is there some easier way to do this? Some common idioms?