Comment #0 by bearophile_hugs — 2014-04-26T15:35:46Z
I suggest to add to std.typecons a cons named "ErrorMsg" (or a similar name) that is meant as a standard way to return an error condition when you don't want to use exceptions (useful in nothrow code).
The advantage over Nullable is that it's not just "null" or a value. ErrorMsg is a value or a error message, so it informs what the cause of the failure is. To avoid generating many unused error message strings, I suggest the error message to be not just a string, but a 0-arguments callable that returns a string lazily.
The advantage over using a user defined struct or Algebraic is that this is standard, so it gives a standard API, and the lazyness of the error message allows to save computation time to generate the error string.
(A similar algebraic is used in other functional languages.)
Comment #1 by robert.schadek — 2024-12-01T16:20:54Z