January 2020
Intermediate to advanced
532 pages
13h 31m
English
A singleton type is just a data type that is designed to have a single instance. In Julia, it can be implemented easily by defining a type without any field:
struct OpenCommand end
To create a single instance of such a data type, we can use the following default constructor:
OpenCommand()
Unlike in some object-oriented programming languages, this constructor returns exactly the same instance, even if you call it multiple times. In other words, it is already a singleton. We can prove this like so:

After creating two instances of OpenCommand, we compare them using the === operator, which tells us that these two ...
Read now
Unlock full access