Hi everyone!

I'm working on getting a better hang of generics. I found generics can use type 
inference if the object is passed as a parameter, but needs to be explicitly 
stated if it is a return value.
    
    
    type
      Foo = object
        foo: int
        bar: int
    
    proc init[T](): T =
      result = T()
    
    proc stringify[T](o: T):string =
      return $o
    
    # fails with "cannot instantiate"
    # let t:Foo = init()
    
    # works
    let t = init[Foo]()
    
    # works
    echo stringify(t)
    
    
    
    
    Run

Is this how it's supposed to work or did I miss something?

Reply via email to