Maybe this is not possible, or I'm missing something. Given the following example: converter floatToInt(f: float): int = f.int # allow conversion type Point[T] = object x: T y: T proc point[T](x, y: T): Point[T] = return Point[T](x: x, y: y) # this works var a = point(1, 1) # int var b = point(2.1, 2.2) # float echo typedesc a, a echo typedesc b, b # this works a = point[int](b.x, b.y) # this doesn't a = point(b.x, b.y) # ideally I want to do this # a = point(b) Run
Assuming for simplicity that T will be only int or float. The proc point(x, y) above accepts int or float, without the need to specify the type. Here the result is based on the type of the arguments. How can I write a proc that will take a Point object and return another Point, based on the type of the variable it's **assigned** to? So a Point[T] would be converted to a Point[U], where T can be any type (int or float), and U is the type of the variable the result is assigned to. Which could also be any type, possibly even the same type.