为什么具有明确指定的通用类型的 proc 不起作用?

Why proc with generic types specified explicitly is not working?

如果 map 的类型明确指定,示例将无法编译,为什么?

这个有效

import sequtils

let nlist = @[1, 2]
let slist: seq[string] = nlist.map(proc (v: auto): auto = $v)

但这不会:

let slist: seq[string] = nlist.map[int, string](proc (v: auto): auto = $v)

记住map is just a normal proc which accepts two parameters, and you happen to be able to use it as first.map(second), due to the method call syntax, but there are some limitations。事实上,如果您将该代码编写为普通的 proc 调用:

import sequtils

let nlist = @[1, 2]
let slist: seq[string] = map[int, string](nlist, proc (v: auto): auto = $v)

然后编译器不再混淆语法并抛出一个正确的理由:

Error: A nested proc can have generic parameters only when it is used as an operand to another routine and the types of the generic paramers can be inferred from the expected signature.