I am new to F# and am trying to develop a snake game so pardon me if this sounds stupid.
For now, this is the model for the game:
// value objects
type Position = int * int
type Block = { Position: Position }
type Tail = { Blocks: Block list }
type Direction =
| North
| South
| West
| East
//
// entities
type Snake = { Tail: Tail }
type World = { Snake: Snake }
//
To make things simpler when moving the snake, I would like for each Direction to have its own Position, just like:
type Direction =
| North of Position (0, 1)
| South of Position (0, -1)
| West of Position (-1, 0)
| East of Position (0, 1)
so I can just apply it here:
let moveSnakeHead direction snake =
// easily move the snake's head
// tail[0].x += direction.x, tail[0].y += direction.y
However, it seems to me that it is not possible to do that of Position (x, y) inside the discriminated union?
Could someone explain why? I am trying my best to learn types. And what would be the alternatives?