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.
Uh oh!
There was an error while loading. Please reload this page.
-
Desired Behavior
My use case is the following.
I have a library
lib1which is already implemented.I would like to have a library
lib2which contains the same modules aslib1but some hooks are added. However, becauselib1is evolving, I don't want to copy/paste the code oflib1intolib2instead, I would like toinclude lib1inlib2and change the linking process so that the modules included refers to the implementation oflib2and notlib1.I thought that
virtual_librariescould 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_librariesor the feature I want is different.Example
Assume the following structure:
where :
lib1/A.mlis implemented aslet foo = "foo"lib1/B.mlis implemented aslet bar = A.foolib2/A.mlis implemented aslet foo = "foo2"lib2/B.mlis implemented asinclude Lib1.Bbin/main.mlis implemented asFormat.printf "%s@." Lib2.B.barThe result when
mainis compiled as usual is"foo"but I would like to seefoo2instead.This is possible using
ocamlcby givinglib2/A.mlat 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