by okasaki · 4y ago · 0 comments
> The first issue in Haskell is that we can't mutate alice; we instead have to return a new Person value with the updated city.
I don't get it. Ok, so it can't mutate, but why can't haskell have an easy syntax and just return a copy with the updated value? Why does it need this very convoluted way for updating records?
eg you could have {{ }} denote an "update block", and this has some special syntax to change values, add or remove items from lists/dicts and similar
let new_alice = {{ alice.address.city = "Los Angeles",
alice.cart.items += 123 }}Lenses are still more powerful as they can be composed. Consider your (and the record dot) syntax for having to modify alice.cart.items on one branch of the conditional and alice.cart.discount on another branch of the conditional.
Perhaps Haskell needs something similar.
let new_alice = set (address . city) "Los Angeles" $ over (cart . items) (+ 123) alice