mfp / extprot

extprot: extensible binary protocols for cross-language communication and long-term serialization
Other
209 stars 9 forks source link

[feature wish] support polymorphic types in ocaml.type #13

Closed ygrek closed 8 years ago

ygrek commented 8 years ago

example :

$ cat a.proto 
type q 'a = [ 'a ] options "ocaml.type" = "'a list, f, g"
type iq = { i : q<int>; }

$ extprotc a.proto -o /dev/stdout
module Q =
  struct type 'a q = 'a list;; let pp_q pp_a ppf x = Extprot.Pretty_print.pp_list pp_a ppf (g x);; 
  end;;
module Iq =
  struct
    type iq = { i : 'a list };;
    let pp_iq =
      Extprot.Pretty_print.pp_struct
        [ ("Iq.i",
           (Extprot.Pretty_print.pp_field (fun t -> t.i) (Q.pp_q Extprot.Pretty_print.pp_int))) ];;

  end;;

type iq is wrong

mfp commented 8 years ago

Should I merge f59bb45? At first glance it looks OK, and I threw a few protocols I had handy at it and verified the same code (around 50 KLoc) was being generated.

6ac392f (edit: was f59bb45cd) OTOH is a breaking change which would warrant a major version bump, but maybe we could follow a hackish strategy as follows: try to parse using comma separators (will fail on polymorphic types with multiple type parameters), and fall back to semi-colon separators. That should both support polymorphic types and be backwards-compatible. Another possibility is to add a new option using semi-colons like e.g. "ocaml.poly_type".

Edit somehow I missed #16 Will merge up to f59bb4 or d0e4100 and then try to implement the comma -> semicolon fallback.

Edit 2 OK I'm an idiot, hadn't realized you already were doing the comma -> semi-colon fallback. It must be made more robust though, as it stands ('a, 'b, 'c) mytype; fromf; to_f would be split as ('a, 'b and 'c) mytype; fromf; to_f.

ygrek commented 8 years ago

Thanks, indeed, semicolon fallback is now better. (sorry for the late reply)

mfp commented 8 years ago

Thank you for all your work, I know it takes some fortitude to read/hack gen_OCaml.ml and friends :)

ygrek commented 8 years ago

:) it is ok, some concepts are not obvious but there is actually an architecture behind the code, so I get my share of fun. NB I am currently working on adding include, looks like it will be a simple change mostly at parser level.