Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error using "with fields" in OCaml

Tags:

ocaml

I'm working through Real World OCaml and I'm getting a syntax error on the following bit of code:

`# module Logon = struct
    type t =
      { session_id: string;
        time: Time.t;
        user: string;
        credentials: string;
      }
    with fields
  end;;

On running, Utop underlines the word "with" and throws a syntax error. I've tried similar, more simple examples on my own and get the same error. Any thoughts on what's going on?

EDIT: Omitted "}" added.

like image 267
John Binder Avatar asked Sep 03 '26 12:09

John Binder


1 Answers

For ocaml 4.01.0 : In utop : #require "fieldslib.syntax";; is solving the issue. (... do not forget to run opam install fieldslib).

For recent ocaml : (got some hints here ).

opam install ppx_jane fieldslib

#require  "ppx_jane";;
#require "fieldslib";; 
module Logon = struct
    type t =
      { session_id: string;
        time: Time.t;
        user: string;
        credentials: string;
      }
    [@@deriving fields]
  end;;
like image 171
Pierre G. Avatar answered Sep 10 '26 21:09

Pierre G.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!