I'm compiling a module with a function that calls List.assoc, it fails to build giving me "Unbound value List.assoc" ... i've tried other List functions and they work fine, it also works fine in utop.
I can reproduce this by compiling an ml file using corebuild and this code
open Core.Std
let p = [(1,2);(2,3);(3,4)]
in List.assoc 2 p
Here is my build command:
$ corebuild blah.byte + ocamlfind ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short-paths -thread -syntax camlp4o -package bin_prot.syntax -package sexplib.syntax,comparelib.syntax,fieldslib.syntax,variantslib.syntax -package core -o blah.cmo blah.ml
File "blah.ml", line 5, characters 3-13: Error: Unbound value List.assoc Command exited with code 2.
The Core library replaces the standard OCaml
List
module. When youopen Core.Std
you mask OCaml's standardList
with Core'sCore.Std.List
module. TheCore.Std.List.assoc
function does not exist. If you aren't openingCore.Std
in utop then you're most likely still working with OCaml's standard libraryList
module.Core does provide a replacement for this functionality with
List.Assoc
. You can see some documentation here: https://ocaml.janestreet.com/ocaml-core/latest/doc/core_kernel.112.17.00/_build/lib/core_list/#/module:AssocList.Assoc.find_exn
looks like it is a replacement for the stdlib'sList.assoc
.