1

Is it possible to install several versions of the same library in Coq? If yes, how do I choose which version I want to work with?

I work in Windows so any solutions using OPAM are unfortunately not going to help me.

Rincewind
  • 197
  • 1
  • 1
  • 9
  • Do you mean different versions of Coq (8.4, 8.5, 8.8, etc) or do you mean different versions of some development (.v files that are read by Coq)? For the latter, just have them in different directories and specify the LoadPath. – larsr May 18 '18 at 11:01
  • I mean different versions of a set of .v files. If I am unlucky I will also need to change to an older version of Coq, but I hope that Coq is backwards compatible enough. When you say "specify the load path" do I need to do this in each .v file of the library or can this somehow be done globally when installing? This library is quite large and I would like to avoid having to change 100s of files by hand. – Rincewind May 18 '18 at 11:26

2 Answers2

2

The best solution is to actually install the libraries in separate directories, using the proper DESTDIR variable in coq_makefile and then set COQPATH to include the right directories. This is the style Nix and OPAM work.

Non-tested example where Makefile comes from coq_makefile:

$ ( cd lib-v1 && DESTDIR=~/coqlib/lib-v1 make install )
$ ( cd lib-v2 && DESTDIR=~/coqlib/lib-v2 make install )

$ export COQPATH=~/coqlib/lib-v1:$COQPATH
$ coqtop
ejgallego
  • 6,709
  • 1
  • 14
  • 29
  • This sounds like it would be what I am looking for. It is, however, not quite clear to me what you mean yet. The library only has a `makefile` but no `coq_makefile`, do I need to create one? What do you mean with "where `Makefile` comes from `coq_makefile`". Do I need to enter the commands in the `makefile` or in the console? Sorry if theses are stupid questions but the whole makefile stuff is currently just black magic to me. – Rincewind May 23 '18 at 12:51
  • I mean that if you are building the coq library using the standard `coq_makefile` setup [most coq libs work that way], then make will understand the `DESTDIR` variable as to install the library in a particular directory. – ejgallego May 23 '18 at 16:54
0

You can use -R to tell coq that a certain directory corresponds to a certain name space. (note that -R takes two parameters, the directory and the namespace!)

Let's create two directories, and compile the two versions. Note that we must tell coqc already at compilation time that the files in the directory should be in the MyLib name space, not in what default namespace happens to be.

D1=~/Desktop/libv1
D2=~/Desktop/libv2

mkdir $D1; echo "Definition a:=1." > $D1/MyLib.v
(cd $D1; coqc -R . MyLib MyLib.v)

mkdir $D2; echo "Definition a:=2." > $D2/MyLib.v
(cd $D2; coqc -R . MyLib MyLib.v)

Now to use libv1 for MyLib

echo "Require Import MyLib. Print a." | \
coqtop -R $D1 MyLib

(that will print a := 1.) and to use libv2 for MyLib

echo "Require Import MyLib. Print a." | \
coqtop -R $D2 MyLib

(that will print a := 2.)

You can also put the -R flag and its parameters in a _CoqProject file so you don't have to put it on the command line all the time. It is also understood by Proof General.


EDIT: to use the COQPATH variable and not the -R flag:

(cd $D1; coqc MyLib.v) # compile without -R
(cd $D2; coqc MyLib.v)

# specify the dir using COQPATH
echo "Require Import MyLib. Print a." | COQPATH=$D1 coqtop

# or add it to the LoadPath when you're in coqtop interactively
echo "Add LoadPath \"$D1\". Require Import MyLib. Print a." | coqtop
larsr
  • 5,447
  • 19
  • 38
  • If the library is nice and packaged and comes with a makefile etc you should use @ejgallego's answer. – larsr May 19 '18 at 07:24
  • 1
    I think it is always better to use `COQPATH` rather than `-R` to load an external library. In particular, in `_CoqProject`, you can set only the `-R` for the library you are writing, not for its dependencies. (see [this link](https://github.com/coq/coq/issues/4990) for more detail) – eponier May 22 '18 at 09:29
  • Actually, I was suggesting to use `-R` for the compilation, and `COQPATH` to refer to the libraries. You should put `MyLib.v` in the directories `libv1/MyLib` and `libv2/MyLib`. Then `COQPATH=libv1` or `COQPATH=libv2` allows to load `MyLib.MyLib`. – eponier May 22 '18 at 22:14