http://d.puremagic.com/issues/show_bug.cgi?id=8304
Summary: writeln of empty Nullables too Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nob...@puremagic.com ReportedBy: bearophile_h...@eml.cc --- Comment #0 from bearophile_h...@eml.cc 2012-06-26 16:30:32 PDT --- In D you can't print an empty Nullable: import std.stdio: writeln; import std.typecons: Nullable; void main() { Nullable!int ni; writeln(ni); } DMD 2.060alpha: object.Exception@C:\dmd2\src\phobos\std\typecons.d(1218): Enforcement failed But I'd like something similar to Haskell, where you are allowed to print an empty Nullable (named Maybe): ...>ghci GHCi, version 7.0.2: ... Prelude> import Data.Maybe Prelude Data.Maybe> Nothing :: Maybe Int Nothing In D when the Nullable is empty I'd like writeln to print something like "EmptyNullable". As temporarily workaround I've added this method to Nullable, but it's not a good general solution: string toString() const { return this.isNull ? "EmptyNullable": text(get()); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------