|
|
|
|
|
by isaacabraham79
2080 days ago
|
|
No. In languages like F#, you can encode in the type system that the result can be either a customer or an error. And the compiler won't let you "access" the customer until you've safely checked that the result is, indeed, the customer rather than an error. In this way you end up encoding more intent within your types and behaviours rather than implicitly letting the consumer figure it out themselves. |
|
/u/anw's example shows that, in fact, the benefits of the type system are greater than that. Not only can the type system prevent you from accessing data before confirming that the data is present (which is, at the end of the day, not much better than an Optional type, already available in Java and others), but it can also prompt you to "handle" all possible cases.