4 ms·
Because player and position are records, the function could actually be written: moveRight :: Int -> Player -> Player moveRight n p@(Player {pos = curP
by bjterry 13y ago
Because player and position are records, the function could actually be written:
moveRight :: Int -> Player -> Player
moveRight n p@(Player {pos = curPos@(Position {x = curX})) =
p {pos = curPos {x = curX + n}}
In which case it isn't making any assumptions about extra properties. The record pattern-matching syntax isn't the prettiest, though, and I find myself having to look it up every time to remember where the accessor name (pos), parameter name (curPos), and intended pattern (Position...) go relative to the "=" and "@".