I am learning OCaml with a book titled as "Real World OCaml" and so far it works well.
I have a problem with sexp and Sexplib.
# module type M = sig
# type t with sexp
# end;;
This is a textbook example but I have a syntax error in utop, with with
word underlined. Core.Std
is open.
Can anyone explain this? I doubt if they have changed language syntax.
Replace "with sexp
" with [@@deriving sexp]
; this also requires the ppx_sexp_conv
rewriter. Alternatively, you can also use ppx_jane
, which includes all Janestreet PPX rewriters (and is automatically used when you use the corebuild
command).
# #use "topfind";;
# #require "core";;
# #require "ppx_sexp_conv";;
# open Core.Std;;
# module type M = sig type t [@@deriving sexp] end;;
module type M =
sig
type t
val t_of_sexp : Sexplib.Sexp.t -> t
val sexp_of_t : t -> Sexplib.Sexp.t
end
Explanation :
http://blogs.janestreet.com/extension-points-or-how-ocaml-is-becoming-more-like-lisp/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With