如何表达 a 的签名,function它必须this返回它接收(被调用)的参数(或),在打字稿中?有没有一种编程语言可以做到这一点?*
// In TypeScript (or consider it pseudo-code)
class C {
// EXAMPLE 1 – Not polymorphic
chainable(x): this // MUST not only return some C,
{} // but the same instance it was called on
}
// EXAMPLE 2
function mutate<T>(a: T[], x): T[] // MUST return a, not a new Array
{
/* So that this doesn't compile */ return Array.from(a);
/* But this is OK */ return a;
}
function相反, a必须返回一个新实例怎么样?
// EXAMPLE 3
function slice<T>(a: T[], x, y): T[] // MUST return a new Array
❌打字稿
走2?
以下会contract实现上述目标吗?
contract referentiallyIdentical(f F, p P) {
f(p) == p
v := *p
}
type returnsSameIntSlice(type T, *[]int referentiallyIdentical) T
func main() {
var mutate returnsSameIntSlice = func(a *[]int) *[]int {
b := []int{2}
/* Would this compile? */ return &b
/* This should */ return a
}
}
C++20?
以上可以表示为 C++ 吗concept?
神不在的星期二
慕尼黑5688855
相关分类