Zulip Chat Archive
Stream: lean4
Topic: RFC: Partial destructuring
Denis Gorbachev (Sep 18 2023 at 23:00):
structure Person where
name : String
age : Nat
def Centennial (person : Person) : Prop :=
-- let { age } := person -- doesn't work, proposing to implement it
let { name, age } := person
age ≥ 100
We already have destructuring assignment, which is great: let { name, age } := person
. However, partial destructuring assignment doesn't work: let { age } := person
is a syntax error.
Partial destructuring would improve readability, especially for functions on structures with 3+ fields, especially where one field is used multiple times throughout the function.
What do you think?
James Gallicchio (Sep 18 2023 at 23:16):
you can do { age, .. }
which is pretty close :)
Denis Gorbachev (Sep 19 2023 at 01:50):
@James Gallicchio Thanks for the pointer!
Denis Gorbachev (Sep 19 2023 at 01:50):
Wouldn't it be shorter if we could just write { age }
?
James Gallicchio (Sep 19 2023 at 02:25):
It would be shorter, but it is nice to have exhaustivity checks for destructuring patterns by default. It helps you find all the places that might need updating when you change a structure!
Last updated: Dec 20 2023 at 11:08 UTC