Order of parameters in outer constructor matters?

I am playing around with parametric types and constructors. First I have a type and constructor as

julia> struct Foo{T, N}
           val::T
       end

julia> function Foo{N}() where {N}
           return Foo{Int, N}(1)
       end

Calling this new constructors works as expected:

julia> Foo{2}()
Foo{Int64, 2}(1)

If I want the first parameter to be a subtype of Integer, I do it like this:

julia> struct Bar{T<:Integer, N}
           val::T
       end

julia> function Bar{N}() where {N}
           return Bar{Int, N}(1)
       end

Trying to do the same thing as with the Foo constructor I get an error:

julia> Bar{2}()
ERROR: TypeError: in Bar, in T, expected T<:Integer, got a value of type Int64
Stacktrace:
 [1] top-level scope
   @ REPL[20]:1

However, if I swap the parameters

julia> struct Baz{N, T<:Integer}
           val::T
       end

julia> function Baz{N}() where {N}
           return Baz{N, Int}(1)
       end

things work just fine

julia> Baz{2}()
Baz{2, Int64}(1)

Why is this the case?

Try an alias.

julia> struct Bar{T <: Integer, N}
           val::T
       end

julia> const IntBar{N} = Bar{Int, N} where N
IntBar (alias for Bar{Int64})

julia> IntBar{2}(1)
IntBar{2}(1)

julia> IntBar{N}() where N = IntBar{N}(1)

julia> IntBar{2}()
IntBar{2}(1)

That is a solution but not for what I had in mind, I’m sorry I did not specify more clearly before. What I would like from the outer constructor is to declare the type of the field val implicitly, like so

julia> struct Foo{T <: Integer, N}
           val::T
       end

julia> function Foo{N}(val::T) where {N, T}
           return Foo{T, N}(val)
       end

Here the same error is thrown, but if I change the order of the parameters in the declaration of Foo, then, there is no problem.

I tried to so the same thing done in this document I found online here. At In [20], he defines the parametric type for a finite field with characteristic N, but the order of the parameters seemed weird, compared to other Julia code I have seen. Does the order matter in this case, and if it does, why?

The crux of the issue, as far as I get, is that Bar{N} is just an alias for Bar{N, K} where {K}.

So, effectively, Julia parses the function definition as

julia> struct Bar{T<:Integer, N}
           val::T
       end

julia> function (Bar{N, P} where {P})() where {N}
           return Bar{Int, N}(1)
       end

This is why you can’t call Bar{2} at all if the first type parameter of Bar is constrained to a subtype of Integer.