# Selectively bringing constructors or record fields into scope

**URL:** <https://discuss.ocaml.org/t/selectively-bringing-constructors-or-record-fields-into-scope/17821>\
**Category:** Learning\
**Created:** [February 17, 2026, 12:58pm UTC](https://discuss.ocaml.org/t/selectively-bringing-constructors-or-record-fields-into-scope/17821 "2026-02-17T12:58:04Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![jbe](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jbe](https://discuss.ocaml.org/u/jbe)\
**Post date:** [February 17, 2026, 1:37pm UTC](https://discuss.ocaml.org/t/selectively-bringing-constructors-or-record-fields-into-scope/17821/5 "2026-02-17T13:37:00Z")

</div>

The syntax is nice, but comes with a risk:

```auto
module M = struct
  type t = { foo : int; bar : bool }

  let ( = ) a b = a.foo = b.foo
end

let () =
  let a = 1 in
  let b = 2 in
  let _ = M.{ foo = 5; bar = (a = b) } in
  ()

```

The above example won’t compile, again for the same reason as discussed in the other thread.

Another example where this causes problems:

```auto
module M = struct
  type t = { foo : int }
end

let () =
  let z = 5 in
  let x = M.{ foo = z } in
  assert (x.foo = z)

```

That program compiles and runs successfully. However, assume that in a new version of the module, there is a new item:

```diff
 module M = struct
   type t = { foo : int }
+ let z = "zero"
 end

```

Now this would lead to a compiler error. But even worse, consider:

```diff
 module M = struct
   type t = { foo : int }
+ let z = 0
 end

```

Now, this would cause a runtime error.

I know that a lot of these scenarios are unlikely to happen, but they still _can_ happen, so I’d like to try to maintain some code/namespace hygiene here to minimize those risks. And I’m not sure what’s the best approach.

---

_[View the full topic](https://discuss.ocaml.org/t/selectively-bringing-constructors-or-record-fields-into-scope/17821)._
