Search code examples
ocamlopam

Difference between module and package Ocaml


I'm basically trying to follow this stackoverflow answer located in this post:

What is the best module for HttpRequest in OCaml

and I'm running in to problems. When I am trying to run a single file with just

open Lwt ;; 

I am getting and error saying it is an unbound module. I have run the following opam instruction:

opam install lwt

and it did install the correct package.

So I think the problem is the difference between a module and a package, which I don't really understand. I was looking at this question as a possible answer, but I wasn't sure if it was what I needed.

Unbound modules in OCaml

Thanks for the input guys, I'm new to Ocaml and I'm trying to learn the ins and outs of building something.


Solution

  • To use a "package", you must tell the compiler about it explicitly. Unbound module in OCaml usually means one of two things: your made a typo of the module name, or you failed to set a proper module search path. What compiler options do you use?

    If you use ocamlfind, the compilation should look like:

    ocamlfind ocamlc -package lwt -c mymodule.ml

    this instructs the compiler to try to find modules in lwt package installation directory, in addition to the default ones.

    if you do not use ocamlfind.... well, use ocamlfind.