News for hackers. Stuff that matters.
Re:Codata in action, or how to connect FP and OOP by hlasdjlfhalwjk on Monday August 10, 2020 @05:18AM (#24107171)
Some Rust libraries use a trick to make sum types extensible without introducing breaking changes when a new invariant is added. There is a private/undocumented invariant in the type so every pattern match over the type must have a default/catch-all/wildcard branch (e.g. it is not possible to do an exhaustive match by naming all existing variants). By having a default branch, the match is always exhaustive and there will be no error if a new variant is added. For fields in a sum type something similar can be done: an undocumented, hidden field that cannot be used when the variant is destructed. Therefore it can be only partially destructed and in this case it doesn't matter how many other fields there are in the type variant.

Here is an example: https://github.com/rust-lang/regex/blob/master/regex-syntax/...

Re:Codata in action, or how to connect FP and OOP by ori_b on Monday August 10, 2020 @07:23AM (#24108028)
Forcing a default case is a big step back towards dynamic typing.
Re:Codata in action, or how to connect FP and OOP by heavenlyblue on Monday August 10, 2020 @09:45AM (#24109142)
“Hey - we have a solution to your type problem; we just disabled type checking. Genious”