Implicitly converting between int and float is as dangrous as letting your 
children driving a car without letting them go to driving school. Nim doesn't 
implicitly convert them for safety. I think if you really need converting 
between int and float, it should be done explicitly so that you can easily find 
a bug when you get it.

For example:
    
    
    type Point[T] = object
      x: T
      y: T
    
    proc point[T](x, y: T): Point[T] =
      return Point[T](x: x, y: y)
    
    proc ConvertPoint[T](RetType: typedesc; x, y: T): Point[RetType] =
      Point[RetType](x: RetType(x), y: RetType(y))
    
    proc ConvertPoint[T, U](dest: var Point[T]; x, y: U) =
      dest.x = T(x)
      dest.y = T(y)
    
    var
      intP = point(1, 2)
      floatP = point(3.1, 4.2)
    
    intP = ConvertPoint(int, floatP.x, floatP.y)
    echo intP
    
    intP = point(0, 0)
    ConvertPoint(intP, floatP.x, floatP.y)
    echo intP
    
    Run

Reply via email to