mfp/extprot

ocaml.type support for parametric types

ygrek opened this issue · 8 comments

ygrek commented

Consider :

$ cat q.proto 
type l = [ int ] options "ocaml.type" = "int list, f, g"
$ extprotc q.proto
Fatal error: exception Failure("Cannot print \"int list\" this string contains more than one token")

Ideally I would like to be able to write

type list 'a = [ 'a ] options "ocaml.type" = "'a list, f, g"

but this might have some typing complications that I may not be aware of, while the former (specialized type without free variables) seems to be only hindered by printing bug..

ygrek commented

For some reason latest commit handles polymophic types but trips on string list (it generates abstract type instead o_O) but String.t list works. I am puzzled.

mfp commented

On Mon, Jan 11, 2016 at 08:37:56PM -0800, ygrek wrote:

For some reason latest commit handles polymophic types but trips on string list (it generates abstract type instead o_O) but String.t list works. I am puzzled.

String.t also works for me with OCaml 4.02.3, but I get a different error
for string list:

$ cat q.proto 
type l = [ string ] options "ocaml.type" = "string list, f, g"

$ OCAMLRUNPARAM=b compiler/extprotc q.proto 
Parse error in OCaml type: Stream.Error("illegal begin of ctyp")
in
string list
Fatal error: exception Loc.Exc_located(_, _)
Raised at file "camlp4/Camlp4/Struct/Loc.ml", line 306, characters 16-35
Called from file "camlp4/Camlp4/Struct/Grammar/Entry.ml", line 59, characters 57-78
Called from file "gen_OCaml.ml", line 141, characters 4-49
Re-raised at file "gen_OCaml.ml", line 145, characters 10-11
Called from file "gen_OCaml.ml", line 171, characters 57-75
Called from file "gen_OCaml.ml", line 409, characters 14-60
Called from file "gencode.ml", line 322, characters 8-40
Called from file "extList.ml", line 154, characters 9-12
Called from file "extList.ml", line 162, characters 1-13
Called from file "gencode.ml", line 303, characters 15-18
Called from file "extprotc.ml", line 119, characters 21-80
Called from file "option.ml", line 25, characters 13-16


$ cat q2.proto 
type l = [ string ] options "ocaml.type" = "String.t list, f, g"

$ compiler/extprotc q2.proto
$ cat q2.ml 
module L =
  struct
    type l = String.t list;;
    let pp_l ppf x = Extprot.Pretty_print.pp_list Extprot.Pretty_print.pp_string ppf (g x);;

  end;;

Mauricio Fernández

ygrek commented

Looks like it cannot parse any "compound" type starting with lident :(

mfp commented

Worse, it chokes on lident itself :-/ (OCaml 4.02.3, camlp4 4.02+6)

mfp commented

And Camlp4OCamlParser.ml leaves no doubt it should be covered (as if there were any chance it weren't to begin with...):

          | i = a_LIDENT -> <:ctyp< $lid:i$ >>
ygrek commented

One more observation: it works for char char list int64 list but not for int or string.
Also note that Camlp4.Precast.Gram parses all those fine.

ygrek commented

The real reason is the extension of grammar in compiler/parser.ml which modifies Camlp4.PreCast.Gram which conflicts with later usage in compiler/gen_OCaml.ml. Proper fix pushed.

mfp commented

Thank you! The dangers of uncontrolled global side-effects :-/