Destructuring Type Parameters

It’s just that when you write a type with the built-in curly-braces syntax, you have to be explicit. Max{Float64, Foo{Int}} is perfectly legal syntax, and it only errors because the OutputType doesn’t match in the specific Max definition. It makes no sense to allow Max2{Float32, Foo2} syntax as a shorthand for all definitions.

The other part of the issue is that because you didn’t use NodeType to annotate any fields, there wasn’t a default Max constructor method. It makes sense, Max(val) alone cannot tell you the entire NodeType. However, you can make a constructor method that accepts the needed type information. Here’s a quick one, though I bet it could be improved: Max(val, T::UnionAll) = Max{typeof(val), T{typeof(val)} }(val). You then just write Max(1e-20, Foo).

2 Likes