-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add extra deriving option for constant variant constructors #23
Comments
Hi @patricoferris, Can I be assigned to this issue please? |
Hi @desirekaleba, nice that you want to contribute to OCaml! Do you already have OCaml up and running on your computer? |
Cool! So yes: perfect to start working on an issue now! Which one do you prefer? This one here or the one on |
I prefer starting with this one here. |
Cool. Don't hesitate to ask, if you have any questions. |
Hi @pitag-ha, I used the previous days to skill up my OCaml skills. I am looking at the issue description but I don't fully understand how to deal with it. Can this tool be installed via opam so that I can first have a look at the current behavior? |
Hi @desirekaleba, Yes, the deriver can be installed via opam:
Also, I was just about to explain you how to load the deriver into the OCaml toplevel (in OCaml, we say toplevel to what in other languages is called REPL), but I've just tried myself and there might be a bug. I'll have a closer look soon and let you know. In the meanwhile, you can just set up a project with |
Hi @pitag-ha, Yes, I have Ocaml up and running. I also took some time to go through A First Hour with OCaml, although this did not only take an hour. I now have a clear understanding of Ocaml. I can start a new project, write some code, build it and run the executable. I am now looking for a way to first test this tool to fully understand how it works. |
Hi both :)) I just opened PR #30 -- this adds a little contributing guide and also "expect-style tests". The tests in |
Also @pitag-ha
I think there might be (see #22). If you have utop # type t = { name : string } [@@deriving yaml];;
type t = { name : string; }
val to_yaml : t -> [> `O of (string * [> `String of string ]) list ] = <fun>
val of_yaml :
[> `O of (string * Yaml.value) list ] -> (t, [> `Msg of string ]) result =
<fun> |
@pitag-ha just to follow-up, I don't think this is a ppx/ppxlib problem, just a yaml one avsm/ocaml-yaml#60 |
A very common pattern is to want to encode string values as a polymorphic (or not) variant with constant constructors. For example:
The standard
[@@deriving yaml]
deriver has to deal with the possibility of non-constant constructors, so these constant ones are encode asStudent: []
which is annoying because then we have:encoding to the following yaml:
What would be nice is to opt into some string only version that generates the following code:
And additionally an extra little
[@value string]
to override the default of using the constructor name verbatim.The text was updated successfully, but these errors were encountered: