In the past, I have been able to install a package using opam install ...
and then access it from inside utop
using like #require "..."
.
For the past few days, I’ve been having an issue with this. For example, I just installed timedesc
by running opam install timedesc
and when I use #require "timedesc"
in utop
, I get the following response:
Error: Reference to undefined compilation unit `Timedesc_tzlocal'
Hint: This means that the interface of a module is loaded, but its implementation is not.
Did you mean to load a compiled implementation of the module
using #load or by passing it as an argument to the toplevel?
I am a little puzzled about what this means, and what to do about it. Can anyone help? Thanks!
I believe this happens whenever a library depends on another library that makes use of dune’s “virtual libraries”. For example, I see the same behaviour with Irmin in the top-level:
Error: Reference to undefined compilation unit `Digestif'
Hint: This means that the interface of a module is loaded, but its implementation is not.
Did you mean to load a compiled implementation of the module
using #load or by passing it as an argument to the toplevel?
Whatever way the top-level works means you have to decide on a concrete implementation of the interface provided by the dependency. In the case of timedesc
this looks like:
utop # #require "timedesc-tzlocal.unix";;
utop # #require "timedesc-tzdb.full";;
utop # #require "timedesc";;
From a dune
perspective, a given library can program purely against the interface, whereas an executable must decide upon the implementation. Hope this helps, I’m sure someone can explain the exact details a lot better!
1 Like
Thanks, this was really helpful!