|
|
|
|
|
by truculent
830 days ago
|
|
How does it make it more complicated? In my view, you’re moving the potential for failure to a different place (the constructor), rather than changing some fundamental property or introducing new complexity. Is it handling the construction of these types you find complicated? And is it simply not worth the guarantees? |
|
See Rich Hickey's "Maybe Not" talk
OOP solution is to use inheritance. Typical ML solution is to use type-classes.
F# sits in an awkward middle-ground where neither is a perfect fit.
I believe that dependently-typed languages solve this more elegantly.
There's also the syntactic inconvenience of wrapping at construction, where in theory the compiler could figure it out for you.
For example:
Here xs is non-empty, but we must tell the compiler: TypeScript does a better job here (although a great cost!)What you end up with is massive code duplication or lots of extra function calls:
(I say this all as someone who really likes F#)