janestreet / ppx_sexp_conv

Generation of S-expression conversion functions from type definitions
MIT License
88 stars 17 forks source link

Support inline records of OCaml 4.03? #9

Closed liweijian closed 7 years ago

liweijian commented 8 years ago

I tried to test the example from this post:

utop #
type shape =
  | Circle of { center_x: float;
                center_y: float;
                radius: float;
              }
  | Rect of { x_lo: float;
              y_lo: float;
              x_hi: float;
              y_hi: float;
            }
;;
type shape =
    Circle of { center_x : float; center_y : float; radius : float; }
  | Rect of { x_lo : float; y_lo : float; x_hi : float; y_hi : float; }

It works as expected, but there's error when I add [@@deriving sexp]:

utop #
type shape =
  | Circle of { center_x: float;
                center_y: float;
                radius: float;
              }
  | Rect of { x_lo: float;
              y_lo: float;
              x_hi: float;
              y_hi: float;
            }
[@@deriving sexp]
;;
Error: Error while running external preprocessor
Command line: /Users/liweijian/.opam/4.03.0/lib/ppx_deriving/./ppx_deriving '/var/folders/6m/g2c97rl9517201ffjyspkxlw0000gn/T/camlppxa5e248' '/var/folders/6m/g2c97rl9517201ffjyspkxlw0000gn/T/camlppxc2357d'
trefis commented 8 years ago

Inline records are indeed not supported at the moment.

The 4.03-compatible version of our libraries and tools was meant as "a preview"/"an alpha release": we released it during the beta of the compiler so people could start trying their codebase with the new compiler. In particular the main interest was to work with existing (4.02) code, supporting new features of the language was not required.

We are going to switch to 4.03 internally very soon, at which point we will release new versions of our libraries which will work with 4.03 and should support these new features.

smolkaj commented 8 years ago

+1 Support for inline records would be very much appreciated :)

ghost commented 8 years ago

It's almost done internally. We are just discussing whether the sexp for A of { x : int; y : int } should be (A (x 1) (y 2)) or (A ((x 1) (y 2)))

smolkaj commented 8 years ago

Any updates on this?

yminsky commented 8 years ago

It's already fixed in our bleeding-edge release, which you can access here:

https://github.com/janestreet/opam-repository

smolkaj commented 8 years ago

Great, thanks!

liweijian commented 7 years ago

I just found that inline records has been supported

type shape =
  | Circle of { center_x: float;
                center_y: float;
                radius: float;
              }
  | Rect of { x_lo: float;
              y_lo: float;
              x_hi: float;
              y_hi: float;
            }
[@@deriving sexp]
;;
type shape =
    Circle of { center_x : float; center_y : float; radius : float; }
  | Rect of { x_lo : float; y_lo : float; x_hi : float; y_hi : float; }