Difference between module and package Ocaml

跟風遠走 提交于 2019-12-07 04:08:13

问题


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.


回答1:


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.




回答2:


The command for compiling our program will be:

ocamlfind ocamlopt -o progprog -linkpkg \
  -package lablGL,sdl,sdl.sdlimage,sdl.sdlmixer,sdl.sdlttf \
  module1.ml module2.ml

As seen on: https://ocaml.org/learn/tutorials/compiling_ocaml_projects.html



来源:https://stackoverflow.com/questions/16681939/difference-between-module-and-package-ocaml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!