as the title suggests, I want to create a parametric type with the value of a custom type as type parameter. So for example
struct MyType
x::Int
end
struct MyParametricType{T}
x
MyParametricType(a) = new{a}(a)
end
This constructor works for “simple” inputs like MyParametricType(5) returns MyParametricType{5}(5). However this does not work for any instance of MyType (even though it is a bitstype) or a String. I also noticed that it does work for a singleton type defined like struct MySingletonType end.
I guess it has something to do with whether Val is defined for my input to MyParametricType.
So is it possible to attain this? And when does it work and when doesn’t it?
Both abstract and concrete types can be parameterized by other types. They can also be parameterized by symbols, by values of any type for which [isbits](https://docs.julialang.org/en/v1/base/base/#Base.isbits) returns true (essentially, things like numbers and bools that are stored like C types or structs with no pointers to other objects), and also by tuples thereof.
Works. I guess there is some special treatment for Symbols, but then I had hoped that MyParametricType(MySymbolType(:a)) also works.
But apparently that is not the case.
Symbols are also special cased here, yes, as mentioned in the quoted section above:
They can also be parameterized by symbols, by values of any type for which isbits returns true (essentially, things like numbers and bools that are stored like C types or structs with no pointers to other objects), and also by tuples thereof.