Stdcompat is a compatibility layer allowing programs to use some
recent additions to the OCaml standard library while preserving the
ability to be compiled on former versions of OCaml.
Stdcompat API is not intended to be stable, but there will be
efforts to allow future versions of
Stdcompat to be compiled on a
large range of versions of OCaml:
Stdcompat should compile (at least)
on every version of OCaml from 3.08 (included).
Stdcompat provides some definitions for values and
types introduced in recent versions of the standard library. These
definitions are just aliases to the matching definition of the standard
library if the latter is recent enough. Otherwise, the module
Stdcompat provides an alternative implementation.
The signature of
Stdcompat follows the signature of the standard library.
All the modules are defined as sub-modules of
Stdcompat.Stdlib, such as
Stdcompat.Stdlib.List, etc. The module
Stdcompat.Stdlib.Pervasives is included in
Stdcompat.Stdlib is included in
For instance, the function
Stdcompat.really_input_string is an alias for
which is an alias for
which is itself an alias for
Pervasives.really_input_string when the version of the OCaml
compiler is above 4.02.0, or an alternative definition otherwise.
Stdcompat.floatarray are aliases
to the built-in ones is the latter are available (above 4.02.0 for
bytes and above 4.06.0 for
floatarray), and are aliases to
float array respectively otherwise.
Sub-modules match the names of the standard library modules. For
Stdcompat.List.find_opt is an alias for
List.find_opt on 4.05.0 and above, or an alternative definition
otherwise. Definitions from the standard library are reexported so that
Stdcompat can be open without hiding unchanged definitions.
are redefined to provide the additional definitions appeared on recent
Seq.t are not
provided by the standard library and if the compatibility packages
seq are available via
then the types
Stdcompat.Seq.t are defined as alias to the types defined in
those packages (these packages should then appear before
in the linking chain).
Some redefinitions access to the internal representation of
the data structures when they are abstracted: it is the case for
Pure (but less efficient) implementations are available by configuring
Redefinitions cannot even guarantee some security fixes: for instance,
seeds and randomization are ignored with
Hashtbl prior to 4.00.0.
See the generated documentation (in
doc/) for available
Configure and install
make -f Makefile.bootstrap first, to generate the files
Makefile.in and others.
./configure --disable-magic to use
the pure and less efficient implementation).
stdcompat can be used on Windows, both with Cygwin and with
Microsoft Visual Studio port.
The build system relies on
therefore the easiest way to compile
stdcompat is to use Cygwin
for compiling, with the same environment as for compiling OCaml:
cl.exeshould be in
PATH: for instance, with Microsoft
Visual Studio 2017 Community, the
PATHcan be initialized with
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat";
should have been executed, so that the command
to the right tool;
ocamlc.exe, etc., should be in