janestreet / ppx_compare

Generation of comparison functions from types
MIT License
22 stars 3 forks source link

Unbound value `compare_int` #5

Closed jnfoster closed 7 years ago

jnfoster commented 7 years ago

Using the latest version of the library available on OPAM,

# Installed packages for 4.04.1:
base                         v0.9.2  Full standard library replacement for OCaml
base-bigarray                  base  Bigarray library distributed with the OCaml
base-bytes                     base  Bytes library distributed with the OCaml co
base-num                       base  Num library distributed with the OCaml comp
base-threads                   base  Threads library distributed with the OCaml 
base-unix                      base  Unix library distributed with the OCaml com
camomile                      0.8.5  A comprehensive Unicode library
conf-m4                           1  Virtual package relying on m4
cppo                          1.5.0  Equivalent of the C preprocessor for OCaml 
jbuilder                 1.0+beta10  Fast, portable and opinionated build system
lambda-term                    1.11  Terminal manipulation library for OCaml
lwt                           3.0.0  Monadic promises and concurrent I/O
lwt_react                     1.0.1  Helpers for using React with Lwt
num                               0  The Num library for arbitrary-precision int
ocaml-compiler-libs          v0.9.0  OCaml compiler libraries repackaged
ocaml-migrate-parsetree       1.0.1  Convert OCaml parsetrees between different 
ocamlbuild                   0.11.0  OCamlbuild is a build system with builtin r
ocamlfind                     1.7.3  A library manager for OCaml
ppx_ast                      v0.9.1  OCaml AST used by Jane Street ppx rewriters
ppx_compare                  v0.9.0  Generation of comparison functions from typ
ppx_core                     v0.9.0  Standard library for ppx rewriters
ppx_deriving                    4.1  Type-driven code generation for OCaml >=4.0
ppx_driver                   v0.9.1  Feature-full driver for OCaml AST transform
ppx_metaquot                 v0.9.0  Write OCaml AST fragment using OCaml syntax
ppx_optcomp                  v0.9.0  Optional compilation for OCaml
ppx_tools                       5.0  Tools for authors of ppx rewriters and othe
ppx_traverse_builtins        v0.9.0  Builtins for Ppx_traverse
ppx_type_conv                v0.9.0  Support Library for type-driven code genera
react                         1.2.1  Declarative events and signals for OCaml
result                          1.2  Compatibility Result module
sexplib                      v0.9.1  Library for serializing OCaml values to and
stdio                        v0.9.0  Standard IO library for OCaml
topkg                         0.9.0  The transitory OCaml software packager
utop                          2.0.1  Universal toplevel for OCaml
zed                             1.5  Abstract engine for text edition in OCaml

I get generate errors for base types:

─────────────────────────────────────────┬─────────────────────────────────────────────────────────────┬─────────────────────────────────────────
                                         │ Welcome to utop version 2.0.1 (using OCaml version 4.04.1)! │                                         
                                         └─────────────────────────────────────────────────────────────┘                                         

Type #utop_help for help about using utop.

─( 09:15:23 )─< command 0 >───────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # #require "ppx_compare";;
─( 09:15:23 )─< command 1 >───────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # type t = int [@@deriving compare];;
Error: Unbound value compare_int                                                                                                                 ─( 09:15:25 )─< command 2 >───────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # 
ghost commented 7 years ago

The comparators for predefined types are available in the module Ppx_compare_lib.Builtin. We usually use ppx_compare with Base or Core, which re-export them

jnfoster commented 7 years ago

Indeed, that was the culprit. Thanks for the quick response!

(This was a minimal example extracted from some older code I was porting to v0.9. It previously didn't open Core but somehow worked...)