With default arguments, in the worst case you can do this:
    
    
    proc f[T](x: typeOrSeqType(proc(y: string): T)) =
      discard
    
    proc f() = f(p)
    
    
    Run

The issue here is generic inference with double generic parameters. In reality, 
due to [implicit 
generics](https://nim-lang.org/docs/manual.html#generics-implicit-generics), 
`f` becomes:
    
    
    proc f[T; U: typeOrSeqType(proc(y: string): T)](x: U = p) =
      discard
    
    
    Run

Normally `U` can be inferred from the default argument, but there is no 
mechanism to infer `T` from `U`. For example, the following works:
    
    
    proc foo(a: int | string = 3) = discard
    foo()
    
    
    Run

But not this:
    
    
    proc foo[T; U: T](a: U = 3) = discard
    foo()
    
    
    Run

Unfortunately I can't think of a good workaround other than the manual overload.

Reply via email to