Bug 12654 – std.typecons.ErrorMsg

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-26T15:35:46Z
Last change time
2024-12-01T16:20:54Z
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: phobos#10050 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10050 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB