Hacker News new | ask | show | jobs
by kvb 3909 days ago
But someone else could create a subclass breaking the invariants. It's possible to avoid this by making the abstract class's constructor private and nesting the two subclasses inside of the abstract class, but this is not idiomatic. If you have to work that hard then most people won't bother, while in F# it's very natural to create such a design.
2 comments

I do not understand how you want to break the invariants by subclassing. My ActiveUser can be deleted and my DeletedUser can be reactivated. How do you break that?
It is easy to do in C# and I do it often (seal your concrete subclasses if you are paranoid). F# does provide better syntax for it though...I wouldn't be surprised if under the covers they are using classes. C# still doesn't provide pattern matching to make it very useful...but someday I hope that happens.
Yes, it does use classes under the covers. I've never consistently used an OO language before, but I've been using C# lately, and knowing how F# can be built on top of a VM that was built for C# has definitely helped me to bring some of these concepts with me. I'm probably not writing idiomatic C#, but I think I'm okay with that.