|
|
|
|
|
by waltpad
2169 days ago
|
|
I think another interesting question is, how would you handle the return value of such function in your code? You would have to either: - test for the type of that value in order to handle it properly, - rely of the implicit cast rules of JS, which wouldn't be very useful here I suppose As it has been said by others, in Ocaml (as well as in many other strongly typed languages) you can use a sum type to solve that problem. Edit: In some languages, there is also the concept of "intersection types" which, if I understand correctly, let one also handle that sort of situation. The corresponding Wikipedia entry [1] gives a list of languages supporting that concept, and provides examples. [1]: https://en.wikipedia.org/wiki/Intersection_type |
|