Type vs tuple that contains a type, Type vs DataType

Is there a rationale for the failure here:

julia> Val(Int)
Val{Int64}()

julia> Val((Int,))
ERROR: TypeError: in Type, in parameter, expected Type, got a value of type Tuple{DataType}
Stacktrace:
 [1] Val(x::Tuple{DataType})
   @ Base ./essentials.jl:1002
 [2] top-level scope
   @ REPL[2]:1

FTR I think a workaround is to wrap with some parametric type, e.g., with Tuple. So, to give a specific example, Val(Tuple{Int,String}) works, but Val((Int, String)) doesn’t.

Here’s a first-order rationale: Val puts its argument into a type parameter. Type parameters must be isbits or types themselves. Tuples of types aren’t isbits nor are they isa Type.

I’m sure you could go much deeper down this rabbit hole. Somewhere down there you’ll find Julia#10380.

4 Likes