【发布时间】:2017-02-06 15:27:35
【问题描述】:
我使用 sexp 序列化了以下 ocaml 记录类型
module User =
struct
type id = int (*Uuid.t*) [@@deriving sexp]
module UserName =
struct
type id = string [@@deriving sexp]
type userId = {user_id: User.id} [@@deriving sexp]
type eff = Add of userId | GetId [@@deriving sexp]
let effToString x = Sexp.to_string (sexp_of_eff x)
let stringToEff x = (*let y = string_before x 24 in
eff_of_sexp (sexp_of_string (string_after y 1))*)
eff_of_sexp (Sexp.of_string x)
let id_to_str x = x
end
上述记录的示例 sexp 类似于 (Add((user_id 756438)))
我将 sexp 转换为字符串,以便使用
将其嵌入到 json 中let effToString x = (*Sexp.to_string_hum*) Sexp.to_string (sexp_of_eff x)
我正在尝试使用以下代码将 sexp 字符串反序列化回记录类型
let stringToEff x = eff_of_sexp (sexp_of_string x)
我收到了错误
Fatal error: exception (Sexplib.Conv.Of_sexp_error
(Failure "Microblog_app_runtime.UserName.eff_of_sexp: unexpected sum tag")
"\"(Add((user_id 941952)))\"")
我尝试删除转义引号,但它仍然给我同样的错误。有人可以解释错误吗?
【问题讨论】:
标签: ocaml