January 2020
Intermediate to advanced
532 pages
13h 31m
English
Val is a parametric data type that is defined in the Julia Base package. Its purpose is to provide us with an easy way to dispatch using singleton types. The Val type is defined as follows:
struct Val{x} end
How do we create a singleton object? We can use the Val constructor and pass it any value. For example, we can create a singleton type that embeds a value of 1, as follows:

Let's confirm the data type of such an object:

Here, we can see that Val(1) and Val(2) have their own types – Val{1} and Val{2}, respectively. ...
Read now
Unlock full access