coq 8.11.0 incompatible with ocaml 4.10? - ocaml

I am installing coq with opam as per these instructions and have gotten the error message
`No solution for coq: The following dependencies couldn't be met:
- coq → ocaml < 4.10
base of this switch (use '--unlock-base' to force)
I proceeded to switch to ocaml 4.05.0 with the following command
opam switch create with-coq 4.05.0
and could install Coq successfully, but I'd much rather use the updated version of ocaml. Is this an actual incompatibility between Coq and oCaml, or am I doing something wrong?
For added context, I am now using opam 2.0.6, ocaml version 4.05.0, and Coq version 8.11.0. My operating system is macOS. Prior, the only difference was that I tried to use ocaml 4.10.0.
Thank you!

You need the tip of the v8.11 branch or wait for 8.11.1 which should be out shortly.
You don't need to go back to 4.05.0 tho, 4.09 will work fine, tho 4.07.1+flambda is the one I recommend, see https://coq.discourse.group/t/install-notes-on-coq-and-ocaml-versions-configuration/713

Related

OCaml Error: Required module `Core__Core_sys' is unavailable

I'm having trouble linking a very simple OCaml program:
open Core
Format.printf "hello world %s\n" "foobar";;
Format.printf "argv= %s\n" (Sys.get_argv()).(0) ;;
which I compile with
ocamlfind ocamlc -thread -package core visitor.ml
The compile step always generates the error:
Error: Required module `Core__Core_sys' is unavailable
I've pinned version 4.0.9, and I can see the file:
$ ocamlfind query core
/home/ubuntu/.opam/4.09.0/lib/core
and $ ls -la /home/ubuntu/.opam/4.09.0/lib/core shows
-rw-r--r-- 1 ubuntu ubuntu 17891 Dec 3 20:14 core__Core_sys.cmi
-rw-r--r-- 1 ubuntu ubuntu 93777 Dec 3 20:14 core__Core_sys.cmt
-rw-r--r-- 1 ubuntu ubuntu 75659 Dec 3 20:14 core__Core_sys.cmti
-rw-r--r-- 1 ubuntu ubuntu 16958 Dec 3 20:14 core__Core_sys.cmx
I've tried everything I can think of, with no luck. BTW, I notice that the documentation https://ocaml.org/api/Sys.html makes no mention at all of get_argv but if I try just plain Sys.argv I get a warning:
# Sys.argv ;;
Alert deprecated: Core.Sys.argv
[since 2019-08] Use [Sys.get_argv] instead, which has the correct behavior when [caml_sys_modify_argv] is called.
So I conclude that the core OCaml documentation published at ocaml.org is more than two years out of date! How can one obtain up-to-date documentation, ideally documentation that describes these kinds of newbie errors?
A few points. First, it looks like you are on a fairly old version of OCaml. Unless you need to stay on 4.09 for some reason, I highly recommend upgrading to the latest version, 4.13.1. Instructions for installing are here: https://ocaml.org/learn/tutorials/up_and_running.html
In case you have any trouble with that, try upgrading to the latest version of opam (the OCaml package manager) and doing opam update to download the most up-to-date package index.
Second, it looks like you are trying to use Jane Street's Core library, which is a third-party package which is intended as a standard library replacement. As such, it has its own version of the OCaml standard library's Sys module, i.e. Core.Sys. Regarding the alert that you are getting, the Core.Sys.argv value is actually deprecated by Jane Street Core: https://ocaml.janestreet.com/ocaml-core/latest/doc/core/Core__/Core_sys/index.html#val-argv
A single result from get_argv (). This value is indefinitely deprecated. It is kept for compatibility...
This leads us to the final issue, when you try to compile it is unable to find the core package. There are a couple of choices here. First, one option is that the core package and standard library replacement are actually optional; you may not actually need them. If you're an OCaml beginner you could try sticking with the standard library only (so no open Core, no trying to compile with the core package).
Another option, if you decide to keep using the core package, is to the dune build system instead of ocamlfind. Dune is a powerful, modern OCaml build system that handles almost all aspects of package linking during the build, so you don't need to worry about issuing individual compile commands.
Here's what a dune file would look like:
(executable
(name visitor)
(libraries core))
And the visitor.ml file would be in the same directory:
let () =
Printf.printf "hello world %s\n" "foobar";
Printf.printf "argv= %s\n" Sys.argv.(0)
Then you would run:
dune exec ./visitor.exe
The .exe is a dune convention, executables across operating systems are given this extension.
Finally, in source code you never actually need ;;. More about that here: https://discuss.ocaml.org/t/terminate-a-line-with-or-or-in-or-nothing/8941/21?u=yawaramin
Note on documentation being out of date: it would help if you could point us to where you got the instructions that led you to this point of confusion. There is a lot of effort to clean up install instructions and modernize documentation, but unfortunately there are a lot of outdated getting started guides out there. The 'Up and Running' link I provided at the top of this answer is the best resource.
You need to link the package by adding the -linkpkg flag:
ocamlfind ocamlc -thread -package core -linkpkg visitor.ml

Ocaml isn't recognizing List.init in Utop

Anytime I use List.init I get the error Error: Unbound value List.init
I think this is because I have Ocaml 4.03.0 and List.init wasn't introduced until 4.06.0. This would lead me to believe that I need to update my ocaml version, but I haven't been able to figure out how to do this. I've tried many opam options, but nothing has worked so far.
With opam you don't upgrade the compiler, but rather install or switch to another compiler installation. That way you can juggle several different installations with separate sets of compatible packages.
You can print a list of available compiler versions by invoking
opam switch list-available
or to reduce it to only the official releases:
opam switch list-available base-compiler
Install a specific version, say 4.06.0, by invoking
opam switch create 4.06.0
eval $(opam env)
List.init is available from the janestreet Core module, it is not available from the standard library. You have to install core ; it is independent of the ocaml compiler.
opam install core
In utop (Welcome to utop version 2.3.0 (using OCaml version 4.03.0)) :
utop # #require "core";;
utop # Core.List.init;;
- : int -> f:(int -> 'a) -> 'a list = <fun>

OCaml: Can't find version

When I enter ocaml --version it returns
/usr/bin/ocaml: unknown option '--version'.
I installed it using OPAM and ran the instructions
opam init
eval $(opam env)
eval opam env
opam switch create 4.07.0
and everything seemed to go fine. Entering which ocaml returns a correct-looking path. And when entering a terminal session it seems to work fine. I don't see this error mentioned anywhere when I search for it.
OCaml tools are weird and usually do not follow the POSIX guidelines of using double dashes for command line options. At this point probably for historic reasons and because the standard Arg module parses command line arguments this way. In any case, this will do the trick:
ocaml -version

How to install a specific version of ocaml compiler with opam

How can I install a specific version of ocaml compiler (and compatible packages) using opam (or another package manger)?
I took a quick look through the opam documentation, but I don't find a relevant information.
I need ocaml compiler (preferably the native code compiler) to build unison, a software for file synchronization. I need to build unison on two machines using the same version of ocaml, or otherwise unison emits an error and aborts its duty (yiiii!).
I tried building ocaml version 4.04.0 from a tar ball and then using it for building unison, but on one of the machine the build of unison failed with the error message,
make[1]: Entering directory '/home/norio/Downloads/unison/unison-2.48.4_expand/src'
ocamlc -o mkProjectInfo unix.cma str.cma mkProjectInfo.ml
File "mkProjectInfo.ml", line 1:
Error: Error while linking /home/norio/Downloads/unison/ocaml_for_unison/lib/ocaml/unix.cma(Unix):
The external function `unix_has_symlink' is not available
if [ -f `which etags` ]; then \
etags *.mli */*.mli *.ml */*.ml */*.m *.c */*.c *.txt \
; fi
make[1]: Leaving directory '/home/norio/Downloads/unison/unison-2.48.4_expand/src'
I don't want to set off for the quest of unix_has_symlink function and devote myself for the exploration of the swamp of library dependencies where many developers had fallen before the civilization came and package managers were invented.
Is there anything like,
opam install ocamlc-4.04 and opam install all-packages?
Addendum
The error message about unix_has_symlink was observed on a machine running Linux Mint 18 Cinnamon 64 bit. Is this function a part of some unix/linux library, rather than ocaml package?
To create a switch with a particular version of the compiler do
opam switch create <compiler-version>
(Note: for the old opam 1.x it was opam switch <compiler-version>)
E.g.,
opam switch create 4.07.0
Or, if you want to create a fresh new switch that uses the same compiler as some other switch, then the syntax is
opam switch create <name> <compiler-version>
E.g.,
opam switch create myproj 4.07.0
Note, that if <name> is a folder, then a local switch will be created, e.g., opam switch ./myproj 4.07.0 will create a switch directly in the myproj folder.
To start with a specific version, i.e., when you first install opam, just do
opam init --compiler=<version>
E.g.,
opam init --compiler=4.07.0
To list available versions do
opam switch
To see even more, do
opam switch list-available
To install a variant of a compiler, e.g., a compiler with flambda or spacetime, use the following general syntax,
opam switch create <switch-name> ocaml-variants.<version>+options <options>...
E.g.,
opam switch create myswitch ocaml-variants.4.13.0+options ocaml-option-flambda
use opam search ocaml-options for the full list of available options. It is possible to specify several options, e.g.,
opam switch create myswitch ocaml-variants.4.13.0+options ocaml-option-flambda ocaml-option-spacetime ocaml-option-static

z3 OCaml bindings - toplevel

I've built z3 as described here using the ml-ng branch. Everything seems to have completed fine, except when I want to use z3 in the OCaml toplevel (I try to use the FindLib #require command to import what's needed) I get this error:
Error: The external function `n_is_null' is not available
any ideas on what this is, and how I would go about successfully using z3 in the toplevel?
I have just updated the ml-ng branch with a new set of build rules that should build and install a package that also works in the ocaml toplevel. See also the following discussion on codeplex: OCaml bindings status and compilation