Functor unbound value

Hi there,

I am upgrading my project from OCaml 4.10 to OCaml 5.2, but something went wrong during compilation. I declared a custom module through functor, as blow

#use "topfind";;
#require "core";;
open Core;;
module IntSet = Set.Make(Int);;
let a = IntSet.of_list [1] in
let b = IntSet.of_list [2] in
let c = IntSet.union a b in
c;;

It pops

File "file.ml", line 7, characters 8-20:
7 | let c = IntSet.union a b in
            ^^^^^^^^^^^^
Error: Unbound value IntSet.union

As for the system/library information, i have

$ opam list
# Packages matching: installed
# Name                      # Installed # Synopsis
astring                     0.8.5       Alternative String module for OCaml
base                        v0.17.1     Full standard library replacement for OCaml
base-bigarray               base
base-bytes                  base        Bytes library distributed with the OCaml compiler
base-domains                base
base-nnp                    base        Naked pointers prohibited in the OCaml heap
base-threads                base
base-unix                   base
base_bigstring              v0.17.0     String type based on [Bigarray], for use in I/O and C-bindings
base_quickcheck             v0.17.0     Randomized testing framework, designed for compatibility with Base
bin_prot                    v0.17.0     A binary protocol generator
camlp-streams               5.0.1       The Stream and Genlex libraries for use with Camlp4 and Camlp5
capitalization              v0.17.0     Defines case conventions and functions to rename identifiers according to them
chrome-trace                3.16.0      Chrome trace event generation library
cmdliner                    1.3.0       Declarative definition of command line interfaces for OCaml
core                        v0.17.1     Industrial strength alternative to OCaml's standard library
cppo                        1.7.0       Code preprocessor like cpp for OCaml
csexp                       1.5.2       Parsing and printing of S-expressions in Canonical form
dune                        3.16.0      Fast, portable, and opinionated build system
dune-build-info             3.16.0      Embed build information inside executable
dune-configurator           3.16.0      Helper library for gathering system configuration
dune-rpc                    3.16.0      Communicate with dune using rpc
dyn                         3.16.0      Dynamic type
either                      1.0.0       Compatibility Either module
fiber                       3.7.0       Dune's monadic structured concurrency library
fieldslib                   v0.17.0     Syntax extension to define first class values representing record fields, to get and set record fields, iterate and fold over all fields of a record and create new recor
fix                         20230505    Algorithmic building blocks for memoization, recursion, and more
fpath                       0.7.3       File system paths for OCaml
gel                         v0.17.0     A library to mark non-record fields global.
host-arch-x86_64            1           OCaml on amd64 (64-bit)
host-system-other           1           OCaml on an unidentified system
int_repr                    v0.17.0     Integers of various widths
jane-street-headers         v0.17.0     Jane Street C header files
jsonrpc                     1.19.0      Jsonrpc protocol implemenation
jst-config                  v0.17.0     Compile-time configuration for Jane Street libraries
lambda-term                 3.3.2       Terminal manipulation library for OCaml
logs                        0.7.0       Logging infrastructure for OCaml
lsp                         1.19.0      LSP protocol implementation in OCaml
lwt                         5.7.0       Promises and event-driven I/O
lwt_react                   1.2.0       Helpers for using React with Lwt
menhir                      20240715    An LR(1) parser generator
menhirCST                   20240715    Runtime support library for parsers generated by Menhir
menhirLib                   20240715    Runtime support library for parsers generated by Menhir
menhirSdk                   20240715    Compile-time library for auxiliary tools related to Menhir
merlin-lib                  5.2.1-502   Merlin's libraries
mew                         0.1.0       Modal editing witch
mew_vi                      0.5.0       Modal editing witch, VI interpreter
num                         1.5-1       The legacy Num library for arbitrary-precision integer and rational arithmetic
ocaml                       5.2.0       The OCaml compiler (virtual package)
ocaml-base-compiler         5.2.0       Official release 5.2.0
ocaml-compiler-libs         v0.17.0     OCaml compiler libraries repackaged
ocaml-config                3           OCaml Switch Configuration
ocaml-index                 1.1         A tool that indexes value usages from cmt files
ocaml-lsp-server            1.19.0      LSP Server for OCaml
ocaml-options-vanilla       1           Ensure that OCaml is compiled with no special options enabled
ocaml-version               3.6.9       Manipulate, parse and generate OCaml compiler version strings
ocaml_intrinsics_kernel     v0.17.1     Intrinsics
ocamlbuild                  0.15.0      OCamlbuild is a build system with builtin rules to easily build most OCaml projects
ocamlc-loc                  3.16.0      Parse ocaml compiler output into structured form
ocamlfind                   1.9.6       A library manager for OCaml
ocamlformat                 0.26.2      Auto-formatter for OCaml code
ocamlformat-lib             0.26.2      OCaml Code Formatter
ocamlformat-rpc-lib         0.26.2      Auto-formatter for OCaml code (RPC mode)
ocp-indent                  1.8.1       A simple tool to indent OCaml programs
ocplib-endian               1.2         Optimised functions to read and write int16/32/64 from strings and bigarrays
ordering                    3.16.0      Element ordering
parsexp                     v0.17.0     S-expression parsing library
pp                          1.2.0       Pretty-printing library
ppx_assert                  v0.17.0     Assert-like extension nodes that raise useful errors on failure
ppx_base                    v0.17.0     Base set of ppx rewriters
ppx_bench                   v0.17.0     Syntax extension for writing in-line benchmarks in ocaml code
ppx_bin_prot                v0.17.0     Generation of bin_prot readers and writers from types
ppx_cold                    v0.17.0     Expands [@cold] into [@inline never][@specialise never][@local never]
ppx_compare                 v0.17.0     Generation of comparison functions from types
ppx_custom_printf           v0.17.0     Printf-style format-strings for user-defined string conversion
ppx_derivers                1.2.1       Shared [@@deriving] plugin registry
ppx_diff                    v0.17.0     A PPX rewriter that genreates the implementation of [Ldiffable.S].
ppx_disable_unused_warnings v0.17.0     Expands [@disable_unused_warnings] into [@warning "-20-26-32-33-34-35-36-37-38-39-60-66-67"]
ppx_enumerate               v0.17.0     Generate a list containing all values of a finite type
ppx_expect                  v0.17.1     Cram like framework for OCaml
ppx_fields_conv             v0.17.0     Generation of accessor and iteration functions for ocaml records
ppx_fixed_literal           v0.17.0     Simpler notation for fixed point literals
ppx_globalize               v0.17.0     A ppx rewriter that generates functions to copy local values to the global heap
ppx_hash                    v0.17.0     A ppx rewriter that generates hash functions from type expressions and definitions
ppx_here                    v0.17.0     Expands [%here] into its location
ppx_ignore_instrumentation  v0.17.0     Ignore Jane Street specific instrumentation extensions
ppx_inline_test             v0.17.0     Syntax extension for writing in-line tests in ocaml code
ppx_jane                    v0.17.0     Standard Jane Street ppx rewriters
ppx_let                     v0.17.0     Monadic let-bindings
ppx_log                     v0.17.0     Ppx_sexp_message-like extension nodes for lazily rendering log messages
ppx_module_timer            v0.17.0     Ppx rewriter that records top-level module startup times
ppx_optcomp                 v0.17.0     Optional compilation for OCaml
ppx_optional                v0.17.0     Pattern matching on flat options
ppx_pipebang                v0.17.0     A ppx rewriter that inlines reverse application operators `|>` and `|!`
ppx_sexp_conv               v0.17.0     [@@deriving] plugin to generate S-expression conversion functions
ppx_sexp_message            v0.17.0     A ppx rewriter for easy construction of s-expressions
ppx_sexp_value              v0.17.0     A ppx rewriter that simplifies building s-expressions from ocaml values
ppx_stable                  v0.17.0     Stable types conversions generator
ppx_stable_witness          v0.17.0     Ppx extension for deriving a witness that a type is intended to be stable.  In this    context, stable means that the serialization format will never change.  This allow
ppx_string                  v0.17.0     Ppx extension for string interpolation
ppx_string_conv             v0.17.0     Ppx extension for generating of_string & to_string
ppx_tydi                    v0.17.0     Let expressions, inferring pattern type from expression.
ppx_typerep_conv            v0.17.0     Generation of runtime types from type declarations
ppx_variants_conv           v0.17.0     Generation of accessor and iteration functions for ocaml variant types
ppx_yojson_conv_lib         v0.17.0     Runtime lib for ppx_yojson_conv
ppxlib                      0.33.0      Standard infrastructure for ppx rewriters
ppxlib_jane                 v0.17.0     Utilities for working with Jane Street AST constructs
re                          1.12.0      RE is a regular expression library for OCaml
react                       1.2.2       Declarative events and signals for OCaml
result                      1.5         Compatibility Result module
seq                         base        Compatibility package for OCaml's standard iterator type starting from 4.07.
sexplib                     v0.17.0     Library for serializing OCaml values to and from S-expressions
sexplib0                    v0.17.0     Library containing the definition of S-expressions and some base converters
spawn                       v0.15.1     Spawning sub-processes
splittable_random           v0.17.0     PRNG that can be split into independent streams
stdio                       v0.17.0     Standard IO library for OCaml
stdlib-shims                0.3.0       Backport some of the new stdlib features to older compiler
stdune                      3.16.0      Dune's unstable standard library
time_now                    v0.17.0     Reports the current time
topkg                       1.0.7       The transitory OCaml software packager
trie                        1.0.0       Strict impure trie tree
typerep                     v0.17.0     Typerep is a library for runtime types
uchar                       0.0.2       Compatibility library for OCaml's Uchar module
utop                        2.14.0      Universal toplevel for OCaml
uucp                        16.0.0      Unicode character properties for OCaml
uuseg                       16.0.0      Unicode text segmentation for OCaml
uutf                        1.0.3       Non-blocking streaming Unicode codec for OCaml
variantslib                 v0.17.0     Part of Jane Street's Core library
xdg                         3.16.0      XDG Base Directory Specification
yojson                      2.2.2       Yojson is an optimized parsing and printing library for the JSON format
zed                         3.2.3       Abstract engine for text edition in OCaml

I checked Core v0.17 documentation, and there is union function in Set. Then why OCaml cannot find it from my custom module?

There is a function Set.union that applies to polymorphic sets (ie Set.t), but there is no such function in the output signature of Set.Make (where the element type is fixed). There is, though, a function union_list that achieves the same purpose: https://ocaml.org/p/core/v0.17.1/doc/Core/Set_intf/module-type-S/index.html#val-union_list.

Cheers,
Nicolas

1 Like

Thank you for your reply! It seems that the Set_intf interface changed from Core 0.14 to Core 0.17. There is a union function from Core 0.14, where the latest version does not.

I am just curious, union is a common function of any set derived from Set.Make, why latest functor interface removes it?

I think you can just use Set.union now. So:

#use "topfind";;
#require "core";;
open Core;;
module IntSet = Set.Make(Int);;
let a = IntSet.of_list [1] in
let b = IntSet.of_list [2] in
let c = Set.union a b in
c;;

Yeah thats right. But what’s the point for Set.Make() if we cannot use functions like union? I mean, the goal of Set.Make() should be a convenient way to design custom set, but I cant quite get it in this case :frowning:

Given that you’re using the janestreet libraries, my thought is that most of the functions in Set do not require the first-class module to be passed. Only certain ones like of_list, singleton, and so on require it, which is one reason why you may want to use Make.

I know that janestreet libraries are industrial strengthen, but I am not sure why it relates to first-class module. Do you mean I can treat Set.Make() from Core as a light-weight way to build my custom set? This makes sense to me. I checked the signature of Set.Make() for both Core 0.14 and Core 0.17. One big difference is 0.17 uses module Diff instead of module Tree. Maybe module Diff is easier to make a light-weight module?