Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between module and package Ocaml

Tags:

ocaml

opam

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.

like image 220
Lilluda 5 Avatar asked May 22 '13 01:05

Lilluda 5


People also ask

What is a module in OCaml?

ocaml modules allow to package together data structures definitions and functions operating on them. This allow to reduce code size and name confusion, as any identifier can appear in different modules, with different meanings, without any interference.

What's the difference between a package and a library?

However, it is often assumed that while a package is a collection of modules, a library is a collection of packages.

What is a .MLI file in OCaml?

In OCaml, the *. mli file is the exported signature of the module, and the compiler strictly enforces it. In most cases for a module called Foo you will find two files: foo.ml and foo. mli . foo.ml is the implementation and foo.

What are Functors in OCaml?

A functor is a module that is parametrized by another module, just like a function is a value which is parametrized by other values, the arguments. It allows one to parametrize a type by a value, which is not possible directly in OCaml without functors.


1 Answers

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.

like image 155
camlspotter Avatar answered Nov 07 '22 03:11

camlspotter