2

I use ocaml with emacs tuareg mode, as a new user I don't really know much about all the ocaml tools...

Recently I installed ocaml-wlc with opam, it's a binding for wayland library in ocaml. I have tried to import the library with open in my code but it doesn't work.

After some research, I found that I need to use ocamlfind, the tool for managing exernal library. I haven't found any tutorial or documentation for this tool on the web, so I read the manual.

After this I still doesn't know how to use the library...

I find that there's a lot of tool for ocaml but I haven't found yet any proper tutorial/documentation about how to use that ecosystem.

The title ask about an ocamlfind tutorial, but in fact I'm looking for a decent tutorial about the ocaml tools ecosystem and how to manage simple tasks like installing and using libraries with opam.

Thank you

  • I wrote a blog post for just this purpose, it will get you up to speed on everything OCaml toolchain, verbiage. http://hyegar.com/blog/2015/10/19/so-you're-learning-ocaml/ –  Dec 19 '15 at 19:16

2 Answers2

1

It contains an example directory showing how to use it:

https://github.com/Armael/ocaml-wlc/tree/master/example

In short, assuming you're using ocamlbuild, put true: package(wlc) in your _tags file.

Thomas Leonard
  • 7,068
  • 2
  • 36
  • 40
  • And the tag would be used by ocaml-find in the `ocamlbuild -use-ocamlfind example.native`command ? And what will do ocaml-find ? Has opam tell him I've installed libray wlc ? – Nicolas Scotto Di Perto Dec 19 '15 at 12:42
1

Use ocamlfind list to get a list of all known ocamlfind packages, respectively of their internal names.

If you have findlib activated in your toplevel (ocaml) then you will get hints about loading packages into the toplevel:

str@s132-intel:~> ocaml
        OCaml version 4.02.3

Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable

To use a package in the toplevel use #require "internalname";; using the name shown by #list;;, only then you can use open.

Side note: open Modulename has the disadvantage to hide where the functions are coming from.

To compile your code, there is an invocation of the compiler prefixed with ocamlfind, see ocamlfind doc here, the general syntax is:

# binary test1, use modules Unix and Str, link packages in
ocamlfind ocamlc -o test1 -packages unix,str -linkpkg test1.ml

Hope this gets you started. See ocaml.org for more information.

And be patient, this is not a mainstream language with tons of material. But you can talk to the researchers and developers directly on their mailing lists.

Str.
  • 1,389
  • 9
  • 14