3 ms·
> They could, but they don't. Now why don't they? One of the bothersome issues is with a `delete :: User -> DeletedUser` method is you now have both a User and
by masklinn 11y ago
> They could, but they don't. Now why don't they?
One of the bothersome issues is with a `delete :: User -> DeletedUser` method is you now have both a User and a DeletedUser, seemingly as valid as the other. Most languages share the issue too, the type-encoding of state change doesn't really work because an instance in the old state is still accessible, at best it might blow up at runtime.
That's a place where affine types (à la Rust) are an improvement, because with `delete(User) -> DeletedUser` you'd completely lose access to the User instance.
- seanmcdirmid 11y agoSome research languages allow for dynamic inheritance in static settings, so ActiveUser -> DeletedUser is a valid transition that can be encoded typefully. However, without affine types and with aliasing, some dynamic checking is obviously needed.
- noblethrasher 11y agoAs I mentioned in my reply to 'geocar, we would need to model the entire state machine, which (usually) means a stack or queue. while(queue.Any()) next_queue.Enqueue(queue.Dequeue().Delete()); So, in this scheme you do lose access to the User instance once you call Delete(). A robust solution would probably involve using the visitor pattern to dispatch the correct Enqueue method of next_queue (i.e. we may have multiple next_queues), but as a side benefit of all that boilerplate, refactoring becomes simple, and you can get concurrency for nearly free.