Problem with parametric composite types

jiang_ming_zhang
Mon, 01 Jan 2024 03:54:55 +0000
General Usage

I defined a type:

struct Point{T}
x :: T
y :: T
end

Then when I tried to construct an variable

b = Point(1.0, 2)

I got

ERROR: MethodError: no method matching Point(::Float64, ::Int64)

Closest candidates are:
  Point(::T, ::T) where T
   @ Main REPL[2]:2

The problem is, aren’t ‘Float64’ and ‘Int64’ both subtypes of ‘Any’? The construction should work if we interprete ‘T’ as ‘Any’, right?

6 posts - 4 participants