Search code examples
ocamluint64opam

using the uint package with OCaml - opam


I just installed opam and installed the uint package. However when I attempt to do something like this

File : Hello.ml
let ash(mystring) = (
    let basis =   uint64.of_string("0xcbf29ce484221325") in
    Printf.printf "Function Finished" ;
);;

ash("Hello");;

I get the error

Error: Unbound value uint64

Any suggestions on what I could be missing ? I am new to OCaml and opam

I used the following statement to compile the code in my OSX terminal

ocaml Hello.ml 

Solution

  • Few issues, you don't need the () around arguments unless you intend them to be a tuple of values (Perhaps a topic you'll learn later down the road)

    Plain ocaml is just like an interpreter, it doesn't know where installed code is (Perhaps you're used to like python where the interpreter has a few places that it looks on its own first)

    let ash mystring =
      let basis = Uint64.of_string "0xcbf29ce484221325" in
      Printf.printf "Function Finished"
    
    let () =
      ash "Hello"
    

    Assuming that is called hello.ml, you can compile it with

    ocamlfind ocamlc -package uint -linkpkg hello.ml -o Test
    

    (This is using the ocamfind wrapper and it calls ocamlc for you and tells it to use the uint package and link it for the final executable called Test)

    and then run it with

    ./Test