Stdcompat: compatibility module for OCaml standard library
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
interface_generator
interfaces
.gitignore
AUTHORS
COPYING
ChangeLog
Dockerfile
INSTALL
Jenkinsfile
META.in
Makefile.am
Makefile.config.in
NEWS
README
README.md
compile
configure.ac
dune
generate_interfaces.sh
install-sh
missing
stdcompat.ml.in
stdcompat.opam
stdcompat__arg.ml.in
stdcompat__arg.mli.in
stdcompat__array.ml.in
stdcompat__array.mli.in
stdcompat__arrayLabels.ml.in
stdcompat__arrayLabels.mli.in
stdcompat__buffer.ml.in
stdcompat__buffer.mli.in
stdcompat__bytes.ml.in
stdcompat__bytes.mli.in
stdcompat__bytesLabels.ml.in
stdcompat__bytesLabels.mli.in
stdcompat__callback.mli.in
stdcompat__char.ml.in
stdcompat__char.mli.in
stdcompat__complex.mli.in
stdcompat__digest.ml.in
stdcompat__digest.mli.in
stdcompat__ephemeron.ml.in
stdcompat__ephemeron.mli.in
stdcompat__filename.ml.in
stdcompat__filename.mli.in
stdcompat__float.ml.in
stdcompat__float.mli.in
stdcompat__format.mli.in
stdcompat__gc.mli.in
stdcompat__genlex.mli.in
stdcompat__hashtbl.ml.in
stdcompat__hashtbl.mli.in
stdcompat__hashtbl_ext.ml.in
stdcompat__hashtbl_ext.mli.in
stdcompat__init.ml.in
stdcompat__init.mli.in
stdcompat__int32.ml.in
stdcompat__int32.mli.in
stdcompat__int64.ml.in
stdcompat__int64.mli.in
stdcompat__lazy.ml.in
stdcompat__lazy.mli.in
stdcompat__lexing.ml.in
stdcompat__lexing.mli.in
stdcompat__list.ml.in
stdcompat__list.mli.in
stdcompat__listLabels.ml.in
stdcompat__listLabels.mli.in
stdcompat__map.ml.in
stdcompat__map.mli.in
stdcompat__marshal.mli.in
stdcompat__moreLabels.ml.in
stdcompat__moreLabels.mli.in
stdcompat__native.ml_byte.in
stdcompat__native.ml_native.in
stdcompat__native.mli
stdcompat__nativeint.ml.in
stdcompat__nativeint.mli.in
stdcompat__obj.mli.in
stdcompat__oo.mli.in
stdcompat__option.ml.in
stdcompat__option.mli.in
stdcompat__parsing.mli.in
stdcompat__pervasives.ml.in
stdcompat__pervasives.mli.in
stdcompat__printexc.mli.in
stdcompat__printf.mli.in
stdcompat__queue.ml.in
stdcompat__queue.mli.in
stdcompat__random.mli.in
stdcompat__result.ml.in
stdcompat__result.mli.in
stdcompat__root.ml.in
stdcompat__root.mli.in
stdcompat__scanf.mli.in
stdcompat__seq.ml.in
stdcompat__seq.mli.in
stdcompat__set.ml.in
stdcompat__set.mli.in
stdcompat__sort.mli.in
stdcompat__spacetime.ml.in
stdcompat__spacetime.mli.in
stdcompat__stack.ml.in
stdcompat__stack.mli.in
stdcompat__stdlabels.mli.in
stdcompat__stream.ml.in
stdcompat__stream.mli.in
stdcompat__string.ml.in
stdcompat__string.mli.in
stdcompat__stringLabels.ml.in
stdcompat__stringLabels.mli.in
stdcompat__sys.ml.in
stdcompat__sys.mli.in
stdcompat__tools.ml.in
stdcompat__tools.mli.in
stdcompat__uchar.ml.in
stdcompat__uchar.mli.in
stdcompat__weak.ml.in
stdcompat__weak.mli.in
stdcompat_tests.ml.in
test_all_switches.sh

README.md

Stdcompat: compatibility module for OCaml standard library

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.

The 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.07 (included).

The module 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.Pervasives, Stdcompat.Stdlib.List, etc. The module Stdcompat.Stdlib.Pervasives is included in Stdcompat.Stdlib, and the module Stdcompat.Stdlib is included in Stdcompat itself. For instance, the function Stdcompat.really_input_string is an alias for Stdcompat.Pervasives.really_input_string, which is an alias for Stdcompat.Stdlib.Pervasives.really_input_string, 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.

The types Stdcompat.bytes and 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 string and float array respectively otherwise.

Sub-modules match the names of the standard library modules. For instance, 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.

Functors Set.Make, Map.Make, Hashtbl.Make, Weak.Make are redefined to provide the additional definitions appeared on recent OCaml releases.

If Pervasives.result, Uchar.t and/or Seq.t are not provided by the standard library and if the compatibility packages result, uchar, and/or seq are available via ocamlfind, then the types Stdcompat.Pervasives.result, Stdcompat.Uchar.t and Stdcompat.Seq.t are defined as alias to the types defined in those packages (these packages should then appear before Stdcompat in the linking chain).

Some redefinitions access to the internal representation of the data structures when they are abstracted: it is the case for {Set,Map,Hashtbl,Queue,Stack}.to_seq*, Hashtbl.filter_map_inplace, Hashtbl.stats, Stack.fold, Set.find*, Set.map. Pure (but less efficient) implementations are available by configuring Stdcompat with ./configure --disable-magic. Note that redefinitions can still have bad time complexity: for instance, Set.map uses the function union to rebuild trees instead of the internal function try_join, because using the latter would require to redefine too much internal functions.

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 definitions.