Closed agarwal closed 4 years ago
For the option problem it should be possible to generate *predef*.None
. This is not documented but compiler accepts that.
On a related note, would it be possible to use fully qualified names for other functions like int_of_sexp in the generated code, thereby removing the requirement of having to do open Sexplib.Std. This would simplify things in a few cases.
int
is not a keyword in OCaml, and the user is free to redefine it. Even if we assume that no one will ever redefine the int
type, it's not uncommon to at least redefine int_of_sexp
or sexp_of_int
. IIRC Core_kernel.Std
does it
int is not a keyword in OCaml, and the user is free to redefine it. Even if we assume that no one will ever redefine the int type, it's not uncommon to at least redefine int_of_sexp or sexp_of_int. IIRC Core_kernel.Std does it
I see, so end users actually have more flexibility the way it is. Okay, thanks for the explanation.
Any update on this? I'm still getting this error in ppx_sexp_conv v0.9.0.
Sorry, not yet no.
BTW, whenever I want a constructor named None
, I just use some other name to avoid the conflict, given how pervasive the option type is. How important is it in your case to use None
?
I just use some other name to avoid the conflict
I would too, but I'm using this for protoc files provided by a 3rd party. My solution right now is to replace NONE
in their files with NOTHING
. That's not too bad, so this isn't a major issue. Only slight negative is that names in our OCaml code don't correspond exactly to the standard as dictated by the protoc files.
I believe this issue was fixed some time ago. The original example works fine today.
Consider the file
a.ml
:Compiling gives this error:
The issue is we have used
None
as a constructor in a new type definition. The generated code foru
includes the normaloption
type constructorsNone
andSome
, but unfortunately type inference ends up requiring these to be of typet
. I'm not sure what the best solution would be. Maybe some explicit type annotations, or fully qualified names for all type constructors (though I can't find whereNone
andSome
are defined.Pervasives.None
doesn't work, so I guess the compiler has special support for these. Sexplib could define an alias to theoption
type and that could be used).On a related note, would it be possible to use fully qualified names for other functions like
int_of_sexp
in the generated code, thereby removing the requirement of having to doopen Sexplib.Std
. This would simplify things in a few cases.