[Issue 8304] New: writeln of empty Nullables too
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Jun 26 16:28:03 PDT 2012
    
    
  
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: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at 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 at 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: -------
    
    
More information about the Digitalmars-d-bugs
mailing list