├── .gitignore ├── CHANGES.md ├── LICENSE.md ├── Makefile ├── README.md ├── dune ├── dune-project ├── result-as-alias-4.08.ml ├── result-as-alias.ml ├── result-as-newtype.ml ├── result.opam └── which_result.ml /.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | *.install 3 | *.merlin 4 | _opam 5 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | 1.5 (17/02/2020) 2 | ---------------- 3 | 4 | - Make Result an alias of Stdlib.Result on OCaml >= 4.08. 5 | 6 | 1.4 (27/03/2019) 7 | ---------------- 8 | 9 | - Switch to Dune. 10 | - Do not refer to Pervasives; it is deprecated. 11 | 12 | 1.3 (05/02/2018) 13 | ---------------- 14 | 15 | - Switch to jbuilder. 16 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Jane Street Group, LLC 2 | All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of Jane Street Group nor the names of his 12 | contributors may be used to endorse or promote products derived 13 | from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | INSTALL_ARGS := $(if $(PREFIX),--prefix $(PREFIX),) 2 | 3 | default: 4 | dune build @install 5 | 6 | install: 7 | dune install $(INSTALL_ARGS) 8 | 9 | uninstall: 10 | dune uninstall $(INSTALL_ARGS) 11 | 12 | reinstall: uninstall reinstall 13 | 14 | clean: 15 | dune clean 16 | 17 | .PHONY: default install uninstall reinstall clean 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Compatibility Result module. 2 | 3 | Projects that want to use the new result type defined in OCaml >= 4.03 4 | while staying compatible with older version of OCaml should use the 5 | `Result` module defined in this library. 6 | -------------------------------------------------------------------------------- /dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name result) 3 | (public_name result) 4 | (modules result)) 5 | 6 | (rule 7 | (with-stdout-to 8 | selected 9 | (run %{ocaml} %{dep:which_result.ml} %{ocaml_version}))) 10 | 11 | (rule 12 | (copy# %{read:selected} result.ml)) 13 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 1.0) 2 | (name result) 3 | -------------------------------------------------------------------------------- /result-as-alias-4.08.ml: -------------------------------------------------------------------------------- 1 | include Stdlib.Result 2 | type ('a, 'b) result = ('a, 'b) Stdlib.Result.t = Ok of 'a | Error of 'b 3 | -------------------------------------------------------------------------------- /result-as-alias.ml: -------------------------------------------------------------------------------- 1 | type nonrec ('a, 'b) result = ('a, 'b) result = Ok of 'a | Error of 'b 2 | type ('a, 'b) t = ('a, 'b) result 3 | -------------------------------------------------------------------------------- /result-as-newtype.ml: -------------------------------------------------------------------------------- 1 | type ('a, 'b) result = Ok of 'a | Error of 'b 2 | type ('a, 'b) t = ('a, 'b) result 3 | -------------------------------------------------------------------------------- /result.opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "opensource@janestreet.com" 3 | authors: ["Jane Street Group, LLC "] 4 | homepage: "https://github.com/janestreet/result" 5 | dev-repo: "git+https://github.com/janestreet/result.git" 6 | bug-reports: "https://github.com/janestreet/result/issues" 7 | license: "BSD-3-Clause" 8 | build: [["dune" "build" "-p" name "-j" jobs]] 9 | depends: [ 10 | "ocaml" 11 | "dune" {>= "1.0"} 12 | ] 13 | synopsis: "Compatibility Result module" 14 | description: """ 15 | Projects that want to use the new result type defined in OCaml >= 4.03 16 | while staying compatible with older version of OCaml should use the 17 | Result module defined in this library.""" 18 | -------------------------------------------------------------------------------- /which_result.ml: -------------------------------------------------------------------------------- 1 | let () = 2 | let version = 3 | Scanf.sscanf Sys.argv.(1) "%d.%d" (fun major minor -> (major, minor)) 4 | in 5 | let file = 6 | if version < (4, 03) then 7 | "result-as-newtype.ml" 8 | else 9 | if version < (4, 08) then 10 | "result-as-alias.ml" 11 | else 12 | "result-as-alias-4.08.ml" 13 | in 14 | print_string file 15 | --------------------------------------------------------------------------------