2 ms·
Good point: things like states, true, false, and nil make sense. I think the commonality there is that those are all immutable values whose only purpose is to
by sah 19y ago
Good point: things like states, true, false, and nil make sense. I think the commonality there is that those are all immutable values whose only purpose is to have a fast object identity comparison. In a way, they're similar to global variables which are all members of the same class, except that it's nice for them to have separate types.
- sah 19y agoIn fact, you could think of Python's None as being a singleton, but True and False being the two allowed instances of a, uh, doubleton? And similarly, states might be implemented as a limited set of allowed values of a single class. This reminds me of Haskell's algebraic types. This maybe isn't quite "Singleton", but it is at least a useful case for limiting the number of allowed values of a class.