I'm trying to work on some code and this is the error that I'm getting.
TypeError: in Type, in parameter, expected Type got xyz
Can anyone explain to me what would theoretically cause this to happen? This error message doesn't help me at all. Thanks!
One way to get this error is the following.
Suppose you have defined a (non-trivial) type XYZ:
julia> struct XYZ
x :: String
end
and an instance of this type:
julia> xyz = XYZ("foo")
XYZ("foo")
You can get the type of object xyz (which is XYZ) using the typeof function:
julia> typeof(xyz)
XYZ
You can get the type of XYZ itself in the same way:
julia> typeof(XYZ)
DataType
however, this will return DataType for all types, which is not so useful when one wants to dispatch on the type of a type. For these cases, there exists the Type "singleton type". I think I have also seen it being referred to as a "pseudo-type", which I find easy to understand: everything works as if the type XYZ was itself of type Type{XYZ}:
julia> XYZ isa Type{XYZ}
true
julia> f(::Type{XYZ}) = 42
f (generic function with 1 method)
julia> f(XYZ)
42
However, there is one thing that you cannot do: build in this way the pseudo-type of an object that is not itself a type:
julia> Type{xyz}
ERROR: TypeError: in Type, in parameter, expected Type, got XYZ
Stacktrace:
[1] top-level scope at REPL[3]:1
In conclusion, you probably used something like Type{xyz} on an object xyz, when what you really wanted was one of the following:
Type{XYZ} to refer to the (pseudo-)type of the type XYZ itselftypeof(xyz) to get the type of object xyzIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With