Deriving sexp error

I have a simple module:

module Action = struct
    type t =
        | Increment
        | Update of int
    [@@deriving sexp]

    let should_log _t = true
end

Compilation results in “Error: Unbound value int_of_sexp”. The same code works in utop. Any idea what’s wrong with this syntax?

No syntax error, but you need to open Base to get the sexp converters for the base types. (You can also get them from Sexplib.)

2 Likes

Deriving sexp and compare are needed to get [%test_eq] to work. Lots of those details are missing in the RealWorldOCaml test chapter… It shows how to compare int list, but not a custom type.

I agree with this idea.
I want to know more about how to use custom types in [%test_eq].