Is there a discrepancy betweeen use of :: and <: in function versus struct definitions

for example:

function foo(x::Real)

end

struct bar{N<:Real}
x::N
end

Why use :: for function, and <: for struct? I get an error with:

struct bar{N::Real}
x::N
end

Someone answered this on Slack. Julia currently does not have the ability to specify concrete type constraints in generic struct definitions.

True, but there’s also no inconsistency here. :: is a typeof annotation, while <: is a subtype annotation. For example, you could have the following:

f(x::N) where {N<:Real}

In both cases N is a type, that’s constrained to be a subtype of Real, which x is a value constrained to be of type N.

5 Likes