Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading a module with dependencies in utop

Tags:

ocaml

utop

I have two modules A.ml and B.ml like so:

A.ml:

type t = int
let from_int (i : int) : t = i

B.ml:

open A
let my_t : t = from_int 0

I can compile them just fine by invoking ocamlc A.ml B.ml however I have no idea how to load them both in utop in order to use my_t interactively. Using:

  • utop -init B.ml yields Error: Reference to undefined global 'A'
  • utop followed by #use "A.ml";; and #use "B.ml";; leads to the same error
  • removing open A from B.ml makes this double #use work but ocamlc A.ml B.ml now fails on B with Error: Unbound type constructor t.
like image 970
gallais Avatar asked Oct 19 '25 09:10

gallais


1 Answers

You have to compile first a.ml :

  ocamlc -c a.ml  // yields a.cmo

in utop :

  #load "a.cmo";;
  #use "b.ml";;
like image 126
Pierre G. Avatar answered Oct 22 '25 06:10

Pierre G.