3 ms·
Feels similar to Kotlin's sealed classes
by caleb-allen 7y ago
Feels similar to Kotlin's sealed classes
- Congeec 7y agoalso Monad in Haskell
- TheAsprngHacker 7y agoHuh? A monad isn't a sealed class, it's a generic type equipped with the functions bind and return...
- james-mcelwain 7y agoThey are similar to Kotlin's sealed classes, except there's no concept in Kotlin of an object "consuming" itself, which is necessary for maintaining safety in the API. For example, in Kotlin, if a method on state A returns state B, there's no way to invalidate all existing references to state A. Normally this invariant would be enforced on the caller's side, or perhaps by throwing an IllegalStateException if state A is called after producing state B.
- Nycto 7y agoAdding to this, I see two other elements that make this tough to replicate in Kotlin: 1. Type erasure 2. Using sealed classes requires instantiation, while the Rust version is zero overhead.
- paulddraper 7y ago> 1. Type erasure There is no need to access type information at runtime here.