Use s-expression in OCaml utop

I am learning OCaml with a book called "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 an example tutorial, but I have a syntax error in utop with an underlined word with. Core.Stdopen.

Can anyone explain this? I doubt that they have changed the syntax of the language.

+4
source share
3 answers

Replace " with sexp" with [@@deriving sexp]; it also requires rewriting ppx_sexp_conv. Alternatively, you can also use ppx_janeone that includes all Janestreet PPX overwrites (and is automatically used when you use the command corebuild).

# #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/

+3

Real World OCaml 2013 , , , OCaml, .

, , . 4.02.1, , .

opam switch 4.02.1

opam , , , utop.

+1

Real Worl Ocaml ocaml 4.01.0 (. ). ocaml Sexplib.syntax( Core)

#require "sexplib.syntax";;

type_conv, sexplib (111.25.00 112.01.00).

>opam install type_conv
0

Source: https://habr.com/ru/post/1665885/


All Articles