Help with error: "N not defined" in method signature but it is

Although this works, this is (strictly speaking) an abuse of the type system: leveraging an undocumented implementation detail that <:Any currently simply doesn’t perform any typecheck on type parameters (after all, 3<:Any throws an error, so it’s nonsensicle that NTuple{3,Int}<:NTuple{<:Any,Int} returns true). As such, when this loophole eventually gets fixed, your code will break.

See this recent discussion for more.

It appears I mistook your intent then: I thought you intended to communicate that the element type of the function’s output tuple is constrained in accordance with the argument’s element type. If not, you could’ve always just written this:

function test(x::Vector, y)::NTuple
    return (1,2,3)
end
1 Like