Parametric Types

Hi there,

I have a quick question regarding types. This is my code:

struct SomeStruct{L}
	v::Vector{Int64}
	
	function SomeStruct{L}() where L::Integer
		new( zeros( Int64, L ) ) 
	end
end

If I want to compile it, I get “invalid variable expression in “where””. I want L to be an Integer and nothing else, e.g.,

S = SomeStruct{5}()

What am I doing wrong? (It works if I don’t specify the type of L)

You can’t check values with parametric signatures, but you can check in the constructor:

using ArgCheck
struct SomeStruct{L}
    v::Vector{Int64}
    function SomeStruct{L}() where L
        @argcheck L isa Integer
	new{L}(zeros(Int64, L))
    end
end
2 Likes

Works! Thank you!