Often I want to use zero-sized structs for dispatch purposes, and it’s kind of annoying to have to make up a name for both the struct and the unique instance of that struct.
In Scala, they have object as a primitive, which creates a class and the unique instance of it in one go. The class is then anonymous, and printed out as Foo.type (or something like that, I can’t remember exactly what).
Would something like this be possible in Julia? It wouldn’t be that hard to do with a macro, using gensym for the name of the struct; but then would it be possible to overload printing out the name of the type to be something more informative than the gensym name?
When you see a capitalized name calling something with parentheses, you may assume it’s a constructor, which returns an object. If there are no input arguments, it’s quite likely a singleton (though it could, admittedly, be a non-singleton with default parameters values.)
I don’t believe it’s good practice to have capitalized functions that have observable side effects, if that’s what you are thinking.
But if you do need this, isn’t that very straightforward?