If I have a type in a module State
type state = {x: int; y: int}
and I have another type in module Game
type game = State.state
how can I access the record values in a object with type game?
For example if I have a game “g”, g.x gives me an “Unbound record field label x” error.
The names of the fields are in the
Statemodule namespace. You can sayg.State.x, or you can open theStatemodule.Or:
If you want the fields to appear in the
Gamemodule namespace, you can repeat them:You can also use the
includefacility to include theStatemodule.For example, your
Gamemodule could say:In either of these cases, you can refer to
Game.x:Or:
There are also two notations for opening a module for just a single expression:
Or:
Edit: Here’s a Unix command-line session that shows the first (simplest) solution: