# Yet another unbound value error

**URL:** <https://discuss.ocaml.org/t/yet-another-unbound-value-error/13247>\
**Category:** Learning\
**Tags:** build, dune\
**Created:** [October 14, 2023, 10:26am UTC](https://discuss.ocaml.org/t/yet-another-unbound-value-error/13247 "2023-10-14T10:26:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NAlec](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@NAlec](https://discuss.ocaml.org/u/NAlec)\
**Post date:** [October 14, 2023, 10:26am UTC](https://discuss.ocaml.org/t/yet-another-unbound-value-error/13247/1 "2023-10-14T10:26:14Z")

</div>

I started with an ocaml file Bataille.ml and finally decided to build a project with dune. The initial set up was as below :

```auto
Bataille
   |---> Bataille.ml

```

Then I added the dune project:

```auto
PS H:\Ocaml\Bataille> cd ..
PS H:\Ocaml> dune init proj Bataille

```

which ended up with the following setup (untouched folders not detailed):

```auto
Bataille
  |--_build
  |--bin
    |-->dune
    |-->main.ml
  |--lib
  |--test
  |-->Bataille.ml
  |-->Bataille.open
  |-->dune-project

```

I slightly modified the main.ml file so that it looks like that :

```auto
let monte_carlos () = 
  let n = 52 in
  let (jeu1,jeu2) = Bataille.init([],[],n) in
  List.iter jeu1 print_int;;

```

As highlighted by `ocamllsp`, when I run a `dune build` I get this error:

```auto
PS H:\OCaml\Bataille> dune build
File "bin/main.ml", line 4, characters 20-33:    
4 | let (jeu1,jeu2) = Bataille.init([],[],n) in
                        ^^^^^^^^^^^^^
Error: Unbound value Bataille.init

```

Which, as a _dune beginner_ (and _ocaml beginner_ as well, I shall confess) am not able to deal with.  
I fear an issue with capital letters here or there, but … this is a mystery for me. I have red somewhere I would not have to declare my modules with dune, it will cope with it … I must have missinterpreted something.

Help appreciated.

---

<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:** [October 14, 2023, 11:16am UTC](https://discuss.ocaml.org/t/yet-another-unbound-value-error/13247/2 "2023-10-14T11:16:34Z")

</div>

> [@NAlec](#):
>
> which ended up with the following setup (untouched folders not detailed):

For a simple executable, the `lib` and `test` directories are not needed (you can delete them). To fix your problem it should be enough to move `Bataille.ml` into the `bin` directory.

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![NAlec](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@NAlec](https://discuss.ocaml.org/u/NAlec)\
**Post date:** [October 14, 2023, 2:51pm UTC](https://discuss.ocaml.org/t/yet-another-unbound-value-error/13247/3 "2023-10-14T14:51:15Z")

</div>

Thank you Nicolas, it worked. Not used to put source code in bin directory but if that’s the way.

---

<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:** [October 14, 2023, 3:42pm UTC](https://discuss.ocaml.org/t/yet-another-unbound-value-error/13247/4 "2023-10-14T15:42:49Z")

</div>

Putting the sources of your executables in the `bin/` directory is just a convention. You are free to put them anywhere you want (even at the root). As long as all the sources and the `dune` file are in the same directory, Dune should have no trouble building your binary.

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:** [October 14, 2023, 6:43pm UTC](https://discuss.ocaml.org/t/yet-another-unbound-value-error/13247/5 "2023-10-14T18:43:07Z")

</div>

Just a note that for a simple beginner project you don’t necessarily need to use `dune init project`, which sets up a general-purpose project structure that’s really more suitable for moderately sized projects. You can just write a couple of dune config files by hand, as shown here: [https://dune.build/](https://dune.build/)
