waleee-cl has quit [Quit: Connection closed for inactivity]
amiloradovsky has quit [Ping timeout: 260 seconds]
efm has joined #ocaml
mfp has quit [Ping timeout: 240 seconds]
dhil has quit [Ping timeout: 260 seconds]
sagax has joined #ocaml
_whitelogger has joined #ocaml
Tekk_ has joined #ocaml
<Tekk_>
Hey, not sure if I'm just not seeing it in the docs but is there a way to derive a yojson serializer for an external type?
<Tekk_>
Like ppx comes with the yojson plugin, but my structs contain UUID types and Uuidm doesn't slap a deriving on Uuidm.t
nullcone has joined #ocaml
malc_ has quit [Ping timeout: 246 seconds]
d0p1 has joined #ocaml
malc_ has joined #ocaml
rfv has quit [Ping timeout: 244 seconds]
j14159_ has quit [Ping timeout: 260 seconds]
JSharp has quit [Ping timeout: 244 seconds]
j14159_ has joined #ocaml
rfv has joined #ocaml
JSharp has joined #ocaml
snowpanda has joined #ocaml
sagax has quit [Ping timeout: 246 seconds]
mbuf has joined #ocaml
mbuf has quit [Client Quit]
narimiran has joined #ocaml
mbuf has joined #ocaml
shmibs has quit [Quit: leaving =o]
shmibs has joined #ocaml
<Tekk_>
I found the "working with existing types" bit for ppx deriving but it doesn't seem to work right? Went and created a new module with t = [%import: Uuidm.t] [@@deriving yojson], changed preprocess to staged_pps with ppx_import at the front of the list, but it complains that there's no value Uuidm.to_yojson.
<Tekk_>
I'm guessing that failure is probably to do with the fact that a Uuidm.t = string rather than some record, but then I'm not sure why yojson isn't able to generate the serializers for it.
NSA_Spy has quit [Ping timeout: 240 seconds]
malc_ has quit [Remote host closed the connection]
narimiran has quit [Ping timeout: 246 seconds]
<Tekk_>
I've worked around this by just defining in my own module to_yojson and of_yojson functions which ought to do the right thing (still not sure about of_yojson atm). It seems like you're not allowed to provide both a to_yojson and of_yojson override though? I've tried pretty much every variant of the [@to_yojson: ...]line I can think of.
spew has quit [Quit: Connection closed for inactivity]
decentpenguin has quit [Read error: Connection reset by peer]
decentpenguin has joined #ocaml
snowpanda has quit [Quit: Leaving...]
vicfred_ has joined #ocaml
vicfred has quit [Ping timeout: 260 seconds]
ggole has joined #ocaml
vicfred_ has quit [Remote host closed the connection]
vicfred_ has joined #ocaml
drewr has quit [Ping timeout: 244 seconds]
drewr has joined #ocaml
sagax has joined #ocaml
mfp has joined #ocaml
Haudegen has joined #ocaml
mbuf has quit [Ping timeout: 240 seconds]
jbrown has quit [Ping timeout: 272 seconds]
jbrown has joined #ocaml
dhil has joined #ocaml
malc_ has joined #ocaml
malc_ has quit [Remote host closed the connection]
malc_ has joined #ocaml
Haudegen has quit [Quit: Bin weg.]
dhil_ has joined #ocaml
dhil has quit [Read error: Connection reset by peer]
mbuf has joined #ocaml
narimiran has joined #ocaml
sagax has quit [Remote host closed the connection]
waleee-cl has joined #ocaml
raver has joined #ocaml
mfp has quit [Ping timeout: 240 seconds]
sagax has joined #ocaml
mfp has joined #ocaml
Yagotzirck has joined #ocaml
NSA_Spy has joined #ocaml
<Tekk_>
Alright, guess it's been 12 hours or so and plenty of joins: Anyone know the proper way to do yojson serialization on types you don't control which aren't records? The deriving import method seems to get confused because the backing type of a Uuidm.t is a string, and I can't figure out what the syntax is to specify both an overridden to_yojson and of_yojson on the field proper.
<Tekk_>
Plus it'd make me specify those on every serializable field of the type which isn't great, but I can live with it.
Haudegen has joined #ocaml
osa1 has joined #ocaml
Haudegen has quit [Ping timeout: 260 seconds]
Haudegen has joined #ocaml
coetry has joined #ocaml
bartholin has quit [Ping timeout: 260 seconds]
FreeBirdLjj has joined #ocaml
tane has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 260 seconds]
osa1 has quit [Ping timeout: 256 seconds]
Yagotzirck has quit [Quit: Leaving]
dhil_ has quit [Ping timeout: 260 seconds]
efm has quit [Read error: Connection reset by peer]
malc_ has quit [Remote host closed the connection]
mbuf has quit [Quit: Leaving]
superherointj has joined #ocaml
narimiran has quit [Ping timeout: 246 seconds]
dhil_ has joined #ocaml
bartholin has joined #ocaml
ggole has quit [Quit: Leaving]
vicfred_ has quit [Quit: Leaving]
superherointj has quit [Quit: Leaving]
coetry has quit [Ping timeout: 256 seconds]
amiloradovsky has joined #ocaml
vicfred has joined #ocaml
jaar has joined #ocaml
Jesin has quit [Quit: Leaving]
Jesin has joined #ocaml
snowpanda has joined #ocaml
<flux1>
Tekk_: you can override both
<flux1>
hmm, I was looking for an example from my own code soo.. :)
<flux1>
(didn't find it)
tane has quit [Quit: Leaving]
<Tekk_>
I'd appreciate it if you know how off the top of your head. obviously I've been changing the file around but I think I've tried foo: Uuidm.t [@to_yojson: ...] [@of_yojson: ...], [@to_yojson: ..., of_yojson: ...], and [@to_yojson: ..., @of_yojson: ...]
<flux1>
how did you create that new module?
<Tekk_>
For the new module I just created a new file. Let me recreate that since I gave up on it.
<Tekk_>
For trying to get derive to derive deserializers
<Tekk_>
I think it was literally just type uuid = [%import Uuidm.t] [@@deriving yojson] in a new file?
<flux1>
you might get better results by defining a module with another name, put the variant module inside it with the correct name and then 'open' it where needed
<Tekk_>
Why's that?
<flux1>
also: I think you can use type my_uuid_type = Uuid.t and if you elsewhere then use my_uuid_type, it will try to use My_uuid_module.of_yojson etc
<flux1>
well, usually it's bad business having duplicate module names
<flux1>
in particualr in the top level scope where there are interface descriptions involved
<Tekk_>
That's fair. It's not duplicated in this case (uuidm vs uuid)
<flux1>
oh, so your module was Uuidm, but it was Uuid you are wrapping?
<Tekk_>
If I follow those instructions I get "Unbound value Uuidm.to_yojson" on a _none_ file
<Tekk_>
Which I assumed was something to do with the fact that the underlying type of Uuidm.t is a string, not a record or anything like that.
<flux1>
so do you refer to type Uuidm.t in your records?
<flux1>
or Uuid.t
<Tekk_>
Normally yes. Just to try it out I changed Uuidm.t to Uuid.t and it has the same error
amiloradovsky has quit [Ping timeout: 240 seconds]
<Tekk_>
type t = [%import: Uuidm.t] [@@deriving yojson]
<Tekk_>
That's the exact line in uuid.ml
<Tekk_>
No difference whether I import or just have Uuidm.t there
<flux1>
you get the error when compiling some module other than your Uuid?
<Tekk_>
I'm actually not sure. The filename is _none_ (I assume due to preprocessing) when I dune build.
<flux1>
did you say you define your own of_yojson/to_yojson for that Uuidm.t?
<Tekk_>
That was plan B,
<Tekk_>
Define an of_yojson and to_yojson in my own module and manually override it every time a record contains a Uuidm.t
<flux1>
well that's not the only option
<flux1>
you can dro pthat [@@deriving yojso], which I believe is the source of the problem
<flux1>
and then define those functions once-and-for-all in your Uuid module
<flux1>
and then use Uuid.t from there on
<flux1>
ok, so the reason why that simple approach fails is because the type Uuidm.t is abstract; it cannot generate the functions for it
<Tekk_>
Is it?
<Tekk_>
I could've sworn that I looked in the source and there was literally type t = string
<flux1>
you maybe looked at the implementation
<flux1>
but the .mli exposes only 'type t'
<Tekk_>
Ahh
<Tekk_>
Alright, so now let's see if my deserializer is wrong.
<flux1>
also about defining both to and of, this works: let foo_of_yojson _ = Ok 42 let yojson_of_foo _ = `String "helo" type t = { foo: int [@of_yojson foo_of_yojson] [@to_yojson yojson_of_foo] } [@@deriving yojson]
<flux1>
of_yojson (`Assoc ["foo", `String "foo"]) and to_yojson { foo = 42 } then work as expected (that is to say: incorrectly :))
<Tekk_>
Mhm, but at least it'd compile. I think I'm just down to my serde functions being bad so I'm going to stub that out like this.
<flux1>
victory is nigh :)
<flux1>
trick if you don't in particular case about the exact format: define a new type that incorporates yjson-compatible types and construct that record, etc
<Tekk_>
Well now I'm onto some weird errors but I can stare at them for a bit. Thanks for the help flux1 c:
<flux1>
good luck :). I guess I need to get some sleep, first work day starts in around 8 hours after a 4-week vacation..
<Tekk_>
Ouch. Good luck playing catchup tomorrow :)
Guest86335 has joined #ocaml
<Tekk_>
flux1: Yeah, had to tweak my serializer and deserializer a touch but I got it.
waleee-cl has quit [Quit: Connection closed for inactivity]
<flux1>
I also discovered your post on /r/ocaml and I'm anxious to see if you answer it or delete it.. ;)