Zulip Chat Archive
Stream: lean4
Topic: Json default arguments
Leni Aniva (May 21 2023 at 17:55):
Is there a way to make fromJson
respect the default values of fields in a structure? e.g.
structure Struct1 where
| n: Nat
| name: String := ""
deriving Lean.FromJson
which would not parse a dictionary of the form {"n": 0}
since the name
field is not supplied
Eric Wieser (May 21 2023 at 18:04):
So by "respect" you mean "ignore the fact they have defaults"?
Eric Wieser (May 21 2023 at 18:05):
This seems a bit of an odd thing to want; if you don't want {"n": 0}
to be legal JSON, do you really still want {n := 0}
to be legal Lean?
Leni Aniva (May 21 2023 at 18:21):
Eric Wieser said:
So by "respect" you mean "ignore the fact they have defaults"?
I want the parser to be able to parse {"n": 0}
instead of giving an error
Eric Wieser (May 21 2023 at 18:22):
Oh, you mean it currently does not parse that input, not that you want it to reject that input!
Eric Wieser (May 21 2023 at 18:22):
I think this is probably just not implemented; we had this feature in Lean 3
Leni Aniva (May 22 2023 at 00:26):
I've submitted an issue for this one: https://github.com/leanprover/lean4/issues/2225
Last updated: Dec 20 2023 at 11:08 UTC