-
Notifications
You must be signed in to change notification settings - Fork 60
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
Type Yojson.Safe.t with equal and show/pp #71
Comments
|
I don't think it should be order-dependent, since these represent JS(ON) objects and these are not ordered as far as I am aware.
|
This would be a welcome change indeed! If we are to expose an I'm not sure type t = [%import: Yojson.Safe.json]
[@@deriving show] I personally use Anyway, if you want to have a go at it, you've got my blessing! |
@NathanReb Glad to hear. This is also how I use I am less sure about Another question is whether this should be implemented manually or whether pulling in |
I definitely think we should use I think |
@NathanReb A word of caution - Think about the following costs, in the scenario where you use ppx_deriving and in the scenario where you don't:
Implementing |
I agree deriving I don't think documenting and ensuring that it works are any tougher with I tend to treat lines of code as a liability and am not a huge fan of re-implementing by hand what's already been done perfectly well elsewhere if I can. My main concern about using Of course if you are strongly against the use of |
This is really your call. I still have a vivid memory of rewriting a bunch
of stuff due to the undocumented "new camlp4" that came around about 10
years ago, and finally reimplementing the json tools with no camlp4 at all
to insure against such future problems. So I'm erring on the conservative
side.
…On Fri, Dec 21, 2018, 03:13 Nathan Rebours ***@***.*** wrote:
I agree deriving compare and equal isn't necessarily the best of ideas
since we want them to have a custom behavior. There's no easy way to do it
strictly with ppx_deriving since the ***@***.*** fun ...] doesn't work with
variants as far as I can tell. I was mostly suggesting we use it for pp
and show and eventually for the other two if that was convenient enough.
I don't think documenting and ensuring that it works are any tougher with
ppx_deriving. Its behavior is well documented. Also I think that might be
a good time to add unit tests and thoroughly test those functions. The CI
would then ensure we don't break the initial behaviour.
I tend to treat lines of code as a liability and am not a huge fan of
re-implementing by hand what's already been done perfectly well elsewhere
if I can.
My main concern about using ppx_deriving for compare and equal here is
that the order will then depend on the order of the variants in the type
declaration if I'm not mistaking (although that could be different for
polymorphic variants). I think as long as the tests pick it up it's an ok
limitation.
Of course if you are strongly against the use of ppx_deriving I won't go
against your will.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#71 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAU84R_pjzPrNHoVX4E2YIhl6SU0EYT1ks5u7MJmgaJpZM4Za5Ii>
.
|
In recent years the OCaml community has converged on some conventions:
t
Yojson is odd in these regards as the type is called
json
(it always trips me up and I have to look it up what it is named), there is no compare function (so I have to write my own) and the pretty printing functions have non-standard names and signatures so I can't just useshow
andpp
asppx_deriving_show
helpfully generates.Therefore I would suggest:
Yojson.Safe.t
while keeping a type aliasjson
to preserve compatibilityequal : 't -> 't -> bool
function in theSafe
moduleshow
/pp
functions in theSafe
moduleI would volunteer of sending a PR, I just want to avoid spending the time implementing to have the suggestions ultimately rejected.
The text was updated successfully, but these errors were encountered: