Code:
module Logon = struct
type t =
{ session_id: string;
time: Time_ns.t;
user: string;
credentials: string;
}
[@@deriving fields]
end;;
let f = Logon.user;; (* added by me *)
Link: Records - Real World OCaml
When I try to compile the above, I get an error of: “Unbound value Logon.user”
project/lib/dune looks like:
(library
(name my_web)
(modes byte)
(libraries
httpaf httpaf-lwt-unix lwt lwt.unix
ppx_jane re
ppx_fields_conv
core core_unix core_unix.sys_unix
stdio base ))
What am I doing wrong ?
I’m using ocaml 5.0.0
On that page they mention quickly,
We need to enable the extension explicitly,
And show how to enable the extension in utop. However they don’t mention how to do it in dune.
Much later in the book they mention:
Using these extensions from a dune
file is as simple as adding this directive to a (library)
or (executable)
stanza to indicate that the files should be run through a preprocessor:
And show an example of how to enable the PPX in dune. You can adapt that example to your PPX, ppx_fields_conv
.
Btw, the book is on GitHub, feel free to file a report about the confusion.
2 Likes
@yawaramin : Thanks
For anyone stumbling across this via search engine: The line that fixed it for me was adding
(preprocess (pps ppx_jane))
to lib/dune
1 Like