Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:41:37+00:00 2026-06-14T20:41:37+00:00

If I have a type in a module State type state = {x: int;

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:41:38+00:00Added an answer on June 14, 2026 at 8:41 pm

    The names of the fields are in the State module namespace. You can say g.State.x, or you can open the State module.

    let f g = g.State.x
    

    Or:

    open State
    
    let f g = g.x
    

    If you want the fields to appear in the Game module namespace, you can repeat them:

    type game = State.state = {x: int; y: int}
    

    You can also use the include facility to include the State module.

    For example, your Game module could say:

    include State
    type game = state
    

    In either of these cases, you can refer to Game.x:

    let f g = g.Game.x
    

    Or:

    open Game
    let f g = g.x
    

    There are also two notations for opening a module for just a single expression:

    let f g = Game.(g.x)
    

    Or:

    let f g = let open Game in g.x
    

    Edit: Here’s a Unix command-line session that shows the first (simplest) solution:

    $ cat state.ml
    type state = { x: int; y : int }
    $ cat game.ml
    type game = State.state
    $ cat test.ml
    let f (g: Game.game) = g.State.x
    
    let () = Printf.printf "%d\n" (f { State.x = 3; y = 4})
    $ ocamlc -o test state.ml game.ml test.ml
    $ ./test
    3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can I access session state from an HTTPModule? I have set up
I have the following simple type: module Structures type Point2D<'T> (x : 'T, y
I have module that implements custom content type via NodeAPI hooks ( hook_insert ,
I have an ArrayList of type modules, each module has an arraylist of Assignments.
Situation: Drupal 6 node module defining custom content type Necessity to have an automated
String is a module and str is a type. I found str have methods,
I have a variable number of modules linked to another module via a signal
Suppose I have some module in vba with some variable r of type Range
I have Python code: cursor.execute('INSERT INTO users (email, password, password_hint, state, last_saved) VALUES (?,
Let's say I have type A, and a derived type B. When I perform

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.