After reading the content on the OCaml web site, the Batteries web site, the OPAM web site, etc, I cannot figure out how to use this library. (It was even worse when I tried Core but I'll stick to batteries for now). Admittedly I'm new to OCaml's ecosystem, but I'm finding it more difficult to understand than Haskell's, than Python's, than Ubuntu's, or any other package-managed system.
So, can someone please tell me how do I get Batteries and OCaml loaded properly so I can start writing code?
I'm on a Mac, so I started here:
brew install opam # Install opam
opam switch 4.01.0 # Install 4.01.0 version of Ocaml
opam install batteries # Install batteries library
eval `opam config env`
ocaml # Run the toplevel
open Batteries # Try to use batteries
I may have left some commands out, but I believe these are the main ones. At the open
command, the toplevel tells me Error: Unbound module Batteries
.
Am I supposed to have to "link" libraries into the Ocaml interpreter because they are not loaded automatically?
Finally, how do I arrive at a working setup that I can then use to learn Ocaml and Batteries?
Load it using findlib in the toplevel:
# #use "topfind";;
# #require "batteries";;
# open Batteries;;
You might like to look at Real World OCaml, which I believe has some instructions for setting up OCaml.
The 'official' way is to use findlib
:
ocamlfind batteries/ocaml
Alternatively, you can tell ocaml
toplevel where to search for batteries modules:
ocaml -I /path/to/batteries/
e.g.
ocaml -I ~/.opam/4.00.1/lib/batteries
or
ocaml -I +batteries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With