# Cannot compile Real World OCaml Examples in Chapter 8: Imperative Programming

**URL:** <https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167>\
**Category:** Learning\
**Tags:** real-world-ocaml\
**Created:** [July 28, 2019, 6:19pm UTC](https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167 "2019-07-28T18:19:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brad\_Sherman](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/brad_sherman/32/1710_2.png) [@Brad\_Sherman](https://discuss.ocaml.org/u/Brad_Sherman)\
**Post date:** [July 28, 2019, 6:19pm UTC](https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167/1 "2019-07-28T18:19:00Z")

</div>

I’m new to Ocaml and I’m trying to go through the Real World OCaml book to learn. I’m getting the following errors compiling the dictionary module and the dlist module from Chapter 8: Imperative Programming:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/2X/3/33e56be4665eb9fe3ead5e2e35800e339bf65602.jpeg)

I’ve copied the code from the second version of the book ([http://dev.realworldocaml.org/imperative-programming.html](http://dev.realworldocaml.org/imperative-programming.html)) which is currently in beta. I’m thinking it could be because of a version mismatch or something along those lines. I’m using version 4.05.0 of ocaml.

Here are the contents of my dune file which I’m using to compile to modules.

```
(executable
  (name dictionary)
  (modules dictionary)
  (libraries base))
(executable
  (name dlist)
  (modules dlist)
  (libraries base))

```

Looking at the code I can’t tell why it’s producing these errors. I’d be happy to provide any other relevant information. Any advice or suggestions on how to fix these errors would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![keleshev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/keleshev/32/3779_2.png) [@keleshev](https://discuss.ocaml.org/u/keleshev)\
**Post date:** [July 28, 2019, 6:29pm UTC](https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167/2 "2019-07-28T18:29:03Z")

</div>

I think if you replace `key' = key` with `Poly.(key' = key)` and `key' <> key` with `Poly.(key' <> key)` it should work.

Whenever you’re using `Base` and suddenly you have spurious `int` in your type error, look for accidental use of `=` and other comparison operators.

---

<div class="post-metadata">

**Author:** ![Brad\_Sherman](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/brad_sherman/32/1710_2.png) [@Brad\_Sherman](https://discuss.ocaml.org/u/Brad_Sherman)\
**Post date:** [July 28, 2019, 6:32pm UTC](https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167/3 "2019-07-28T18:32:59Z")

</div>

worked like a charm! Thanks for the fix and the tip.

---

<div class="post-metadata">

**Author:** ![XVilka](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/xvilka/32/5334_2.png) [@XVilka](https://discuss.ocaml.org/u/XVilka)\
**Post date:** [July 29, 2019, 5:02am UTC](https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167/4 "2019-07-29T05:02:50Z")

</div>

You can also send a pull request to their GitHub repository with a fix: [https://github.com/realworldocaml/book](https://github.com/realworldocaml/book)

---

<div class="post-metadata">

**Author:** ![keleshev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/keleshev/32/3779_2.png) [@keleshev](https://discuss.ocaml.org/u/keleshev)\
**Post date:** [July 29, 2019, 2:27pm UTC](https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167/5 "2019-07-29T14:27:16Z")

</div>

Looks like the fix was merged a few months ago: [https://github.com/realworldocaml/book/pull/3053/files](https://github.com/realworldocaml/book/pull/3053/files), but the web site is out of date.

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [July 31, 2019, 12:05am UTC](https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167/6 "2019-07-31T00:05:11Z")

</div>

Take a look now. It should be up to date…

---

<div class="post-metadata">

**Author:** ![keleshev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/keleshev/32/3779_2.png) [@keleshev](https://discuss.ocaml.org/u/keleshev)\
**Post date:** [July 31, 2019, 12:01pm UTC](https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167/7 "2019-07-31T12:01:06Z")

</div>

As of now, it is still outdated: [https://dev.realworldocaml.org/imperative-programming.html#example-imperative-dictionaries](https://dev.realworldocaml.org/imperative-programming.html#example-imperative-dictionaries)

---

<div class="post-metadata">

**Author:** ![samoht](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/samoht/32/81_2.png) [@samoht](https://discuss.ocaml.org/u/samoht)\
**Post date:** [August 1, 2019, 7:18am UTC](https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167/8 "2019-08-01T07:18:23Z")

</div>

As I’ve indicated in [https://github.com/realworldocaml/book/pull/3053#issuecomment-516441726](https://github.com/realworldocaml/book/pull/3053#issuecomment-516441726) the README.md doc has to be updated too (using mdx or manually). We are in the process of refreshing the tooling a bit so that this kind of update is done automatically by the CI so that these kinds of confusion do not happen anymore.

---

<div class="post-metadata">

**Author:** ![XVilka](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/xvilka/32/5334_2.png) [@XVilka](https://discuss.ocaml.org/u/XVilka)\
**Post date:** [August 1, 2019, 7:48am UTC](https://discuss.ocaml.org/t/cannot-compile-real-world-ocaml-examples-in-chapter-8-imperative-programming/4167/9 "2019-08-01T07:48:15Z")

</div>

There are some dangling pull requests as well: [https://github.com/realworldocaml/book/pulls](https://github.com/realworldocaml/book/pulls)

Also broken syntax highlight in some chapters: [https://github.com/realworldocaml/book/issues/3081](https://github.com/realworldocaml/book/issues/3081)
