Problems using Int as a Real

Hi everyone,
I have a function draw

function draw(state::Vector{Segment}, boundary::Tuple{Vector{Real}, Vector{Real}})
    x(s::Segment) = s.point[1]
    y(s::Segment) = s.point[2]
    display(plot([boundary[1][1]; x.(state); boundary[2][1]], [boundary[1][2]; y.(state); boundary[2][2]], markershape = :circle))

and call it later with

boundary = ([0; 0], [22; 0])

as the second argument.
Why do I get this error message?

LoadError: TypeError: in typeassert, expected Tuple{Vector{Real}, Vector{Real}}, got a value of type Tuple{Vector{Int64}, Vector{Int64}}

Shouldn’t I be able to use Int when a Real is expected?

Change Vector{Real} to Vector{<:Real}.


Thank you, Apparently I did not read that thoroughly enough :sweat_smile:

Why Julia does not do it automatically?

Because then parametric types wouldn’t be invariant but co- or contra-variant. Please follow the link @dilumaluthge gave.

1 Like

This is a noob explanation of that: Vector{Int} <: Vector{Real} is false??? · JuliaNotes.jl

1 Like