Include a module and change the implementation of its dependencies #5743
Replies: 4 comments
-
You need to have one virtual library where |
Beta Was this translation helpful? Give feedback.
-
In practice, the implementation of
include Lib1
let foo = ignore(A.foo); "foo2" (* Redefinition of foo *) I just used |
Beta Was this translation helpful? Give feedback.
-
What about putting the shared code in a shared module |
Beta Was this translation helpful? Give feedback.
-
The workaround by Jeremie is the accepted one. |
Beta Was this translation helpful? Give feedback.
-
Desired Behavior
My use case is the following.
I have a library
lib1
which is already implemented.I would like to have a library
lib2
which contains the same modules aslib1
but some hooks are added. However, becauselib1
is evolving, I don't want to copy/paste the code oflib1
intolib2
instead, I would like toinclude lib1
inlib2
and change the linking process so that the modules included refers to the implementation oflib2
and notlib1
.I thought that
virtual_libraries
could help me but I did a test and the behavior is not the one I expected. I don't really know whether I did something wrong withvirtual_libraries
or the feature I want is different.Example
Assume the following structure:
where :
lib1/A.ml
is implemented aslet foo = "foo"
lib1/B.ml
is implemented aslet bar = A.foo
lib2/A.ml
is implemented aslet foo = "foo2"
lib2/B.ml
is implemented asinclude Lib1.B
bin/main.ml
is implemented asFormat.printf "%s@." Lib2.B.bar
The result when
main
is compiled as usual is"foo"
but I would like to seefoo2
instead.This is possible using
ocamlc
by givinglib2/A.ml
at the linking step, but I did not manage to do it withdune
. One may found the current example in the following archive (using virtual libraries):link.tar.gz.
Beta Was this translation helpful? Give feedback.
All reactions