Module strange behavior

I am using linux mint 21 and ocaml 4.14.0.

My utility module has the structure:
module type UtilsMType = sig

end
module UtilsM : UtilsMType = struct

end

My test program is:
open Printf
(*
open UtilsM
let _ = printf “pi’ = %f\n” pi’
*)
let _ = printf “Utils.pi’ = %f\n” (UtilsM.pi’)

When I run:
ocamlfind ocamlopt -o test -linkpkg -package zarith UtilsM.ml testModule1.ml

I get:
let _ = printf “Utils.pi’ = %f\n” (UtilsM.pi’)
Error: Unbound value UtilsM.pi’

which is not what I was expecting. On a mac m1 with ocaml 4.14.0, I get the correct printout.
If I uncomment
open UtilsM

then the program runs ok. If I uncomment the line
let _ = printf “pi’ = %f\n” pi’

then I get the unbound error for pi’. However if I add a SECOND
open UtilsM
statement, the program runs ok.

The module runs as expected using utop and on the mac m1. Am I missing something??

Can you use code blocks to format the code so that it’s easier to read?

It sounds like this is the contents of your UtilsM.ml file:

module type UtilsMType = sig
  val pi' : float
  ...
end
module UtilsM : UtilsMType = struct
...
end

Is that correct? If so, the “fully-qualified” module path to the value is UtilsM.UtilsM.pi', not UtilsM.pi'. That might explain why the second open was necessary.

Since you mentioned macOS, it’s possible that the case-insensitive filesystem made a difference here, but I don’t have a good idea of how exactly that happened. What happens if you name the file utilsM.ml instead of UtilsM.ml?

You are correct about the contents of the UtilsM.ml file. I used the “fully-qualified” path that you mentioned, and it worked fine. Problem solved.

By the way, what is the simplest way to create code blocks for use in the forum? I looked at markdown editors and nothing seemed easy.

Just enclose code in triple backticks, the highlighting is automatic.