Here's a better example of what I'm talking about.

Imagine you have two files foreignFile.nim and myFile.nim.

foreignFile.nim 
    
    
    template p[T:int|float](a : T) =
      echo "Number:" & $a
    
    template p(a : string) =
      echo "String:" & a
    
    proc printVar*[T:int|float|string](a : T) =
      p(a)
    
    
    Run

All the templates printVar should call are already defined but p isn't bound so 
it can potentially use new templates/procs/etc defined in the future.

myFile.nim 
    
    
    import foreignFile
    
    var x = 0
    
    template p(a : int) =
      x += a
      echo x
    
    p(7)
    
    printVar(5)
    printVar(5.0)
    printVar("5.0")
    
    
    Run

In this example you've inadvertently overwritten p from myFile when aProc is 
passed an int. It will echo 12 instead of Number:5. You only wanted to call 
your new p definition directly. In this case the generic printVar proc should 
probably be three seperate printVar definitions instead of
    
    
    proc printVar*[T:int|float|string](a : T)
    
    
    Run

Reply via email to