Git Product home page Git Product logo

stdcompat's Introduction

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.08 (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.

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.

Configure and install

Execute make -f Makefile.bootstrap first, to generate the files configure, Makefile.in and others.

Then execute ./configure (or ./configure --disable-magic to use the pure and less efficient implementation).

Then execute make and make install.

Windows support

stdcompat can be used on Windows, both with Cygwin and with Microsoft Visual Studio port.

The build system relies on autoconf, automake and make, therefore the easiest way to compile stdcompat is to use Cygwin for compiling, with the same environment as for compiling OCaml:

  • cl.exe should be in PATH: for instance, with Microsoft Visual Studio 2017 Community, the PATH can be initialized with "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat";
  • eval $(<ocaml-source-tree>/tools/msvs-promote-path)" should have been executed, so that the command link.exe points to the right tool;
  • moreover, ocaml.exe, ocamlc.exe, etc., should be in PATH.

stdcompat's People

Contributors

thierry-martinez avatar leonidas-from-xiv avatar hcarty avatar nathanreb avatar gbury avatar crabtw avatar kit-ty-kate avatar olafhering avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.