Syntax Errors in utop when using Sexplib and Fieldslib

71 views
Skip to first unread message

Gabriel Jaldon

unread,
Oct 26, 2016, 1:54:20 PM10/26/16
to ocaml-core
I'm following Real World OCaml and some of the code provided raise Syntax Errors. Below are some of the code:

```
let custom_to_sexp = <:sexp_of<float * string list * int>>;;
```
- The syntax error are on the characters `<:`

```
module Logon = struct
  type t =
    { session_id: string;
      time: Time.t;
      user: string;
      credentials: string;
    }
  with fields
end
```
- syntax error is on `with`

I'm using utop version 1.19.3 and OCaml 4.03.0.

My ~/.ocamlinit file looks like:
```
(* Added by OPAM. *)
let () =
  try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
  with Not_found -> ()
;;

#use "topfind";;
#thread;;
(* #camlp4o;; *)
#require "ppx_jane,core.top";;
#require "async";;
#require "core_extended";;
open Core.Std;;
```

How to make those syntax extensions work with utop?

Yaron Minsky

unread,
Oct 26, 2016, 3:55:31 PM10/26/16
to ocaml...@googlegroups.com
If you're using a recent version of Core, we've made a rather major
switch from using camlp4 to using PPX. We really need to get RWO
updated to match, which we're working on.

Anyway, it looks like you have roughly the right things in your
ocamlinit. You should be able to write:

let custom_to_sexpo = [%sexp_of: float * string list * int]

instead, and that should work. For the Logon, you should be able to write:

module Logon = struct
type t = { ... }
[@@deriving fields]
end
> --
> You received this message because you are subscribed to the Google Groups
> "ocaml-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ocaml-core+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Gabriel Jaldon

unread,
Oct 27, 2016, 12:43:46 PM10/27/16
to ocaml-core
Thanks a lot for the response, Yaron! Apart from some outdated content, the book is great! I'm looking forward to the update. 
Reply all
Reply to author
Forward
0 new messages