# Basic problem with Dune and .mli files

**URL:** <https://discuss.ocaml.org/t/basic-problem-with-dune-and-mli-files/13368>\
**Category:** Ecosystem\
**Tags:** dune\
**Created:** [November 4, 2023, 4:26pm UTC](https://discuss.ocaml.org/t/basic-problem-with-dune-and-mli-files/13368 "2023-11-04T16:26:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ColonelHathi](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@ColonelHathi](https://discuss.ocaml.org/u/ColonelHathi)\
**Post date:** [November 4, 2023, 4:26pm UTC](https://discuss.ocaml.org/t/basic-problem-with-dune-and-mli-files/13368/1 "2023-11-04T16:26:33Z")

</div>

Hi,

I’m new to Dune and OCaml, and I have the fundamental problem that the content of a .mli file is not visible from the corresponding .ml file. I must be missing something very basic.

Minimal example:

```auto
dune init proj myproj

```

(No changes to any dune files after this.)

Add files lib/foo.ml and lib/foo.mli

```auto
(* lib/foo.mli *)
module type Foo_sig = sig
	val content : string
end;;

```

```auto
(* lib/foo.ml *)
module Foo : Foo_sig = struct
	let content = "Success!";;
end;;

```

Replace the code in bin/main.ml

```auto
(* bin/main.ml *)
open Myproj.Foo

let () = print_endline Foo.content

```

This fails with “unbound module type Foo\_sig”. If I copy the code of foo.mli into foo.ml, it works perfectly.

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [November 4, 2023, 5:21pm UTC](https://discuss.ocaml.org/t/basic-problem-with-dune-and-mli-files/13368/2 "2023-11-04T17:21:30Z")

</div>

Hello,

Interfaces (`.mli` files) are not “included” in the corresponding implementations (`.ml` files), so the behaviour you observed is expected: what you write in the `.mli` is not “visible” from the corresponding `.ml`. In fact, in OCaml it works the other way around: `.mli` files are used to **restrict** the visibility of objects defined in `.ml` files, so that eg specific types or values, or details thereof, may be kept private to the implementation, hidden from the users of the module.

You may find working through [Files, Modules, and Programs - Real World OCaml](https://dev.realworldocaml.org/files-modules-and-programs.html#scrollNav-3) useful to learn more about how interfaces and implementations work. You can also find an explanation in the manual [OCaml - The OCaml language](https://v2.ocaml.org/releases/5.1/htmlman/compunit.html), but it is rather concise, so it may not be very useful at this stage.

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![ColonelHathi](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@ColonelHathi](https://discuss.ocaml.org/u/ColonelHathi)\
**Post date:** [November 4, 2023, 7:20pm UTC](https://discuss.ocaml.org/t/basic-problem-with-dune-and-mli-files/13368/3 "2023-11-04T19:20:45Z")

</div>

Hi Nicolas,

thank you very much. So I could instead write:

```auto
(* lib/foo.mli *)
module Foo : sig
	val content : string
end;;

```

```auto
(* lib/foo.ml *)
module Foo = struct
	let content = "Success!";;
end;;

```

(or remove the explicit module declaration/definition entirely).

The pattern of putting a named module type in the .mli is from a project I’m currently looking at (HOLzero). There it works because everything (.mli and .ml) is just thrown into the toplevel by `#use` or something similar.

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [November 4, 2023, 7:54pm UTC](https://discuss.ocaml.org/t/basic-problem-with-dune-and-mli-files/13368/4 "2023-11-04T19:54:52Z")

</div>

> [@ColonelHathi](#):
>
> So I could instead write:

Yes, exactly.

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [November 5, 2023, 4:05am UTC](https://discuss.ocaml.org/t/basic-problem-with-dune-and-mli-files/13368/5 "2023-11-05T04:05:42Z")

</div>

Small note, in source code you don’t need `;;`

---

<div class="post-metadata">

**Author:** ![ColonelHathi](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@ColonelHathi](https://discuss.ocaml.org/u/ColonelHathi)\
**Post date:** [November 5, 2023, 7:54am UTC](https://discuss.ocaml.org/t/basic-problem-with-dune-and-mli-files/13368/6 "2023-11-05T07:54:33Z")

</div>

@yawaramin Good point, thank you!
