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

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:

I’ve copied the code from the second version of the book ( 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.

  (name dictionary)
  (modules dictionary)
  (libraries base))
  (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!

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.

1 Like

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

1 Like

You can also send a pull request to their GitHub repository with a fix:

Looks like the fix was merged a few months ago:, but the web site is out of date.

1 Like

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

As of now, it is still outdated:

As I’ve indicated in the 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.

1 Like

There are some dangling pull requests as well:

Also broken syntax highlight in some chapters: