E4000

E4000#

类型变量名称已被使用。

错误示例#

///|
struct Container[T, T] {
  value : T
}

///|
fn[A, A] transform(x : A) -> A {
  x
}

建议#

使用不同的类型变量名称:

///|
priv struct Container[T1, T2] {
  first : T1
  second : T2
}

///|
fn[A, B] transform(x : A, f : (A) -> B) -> B {
  f(x)
}

///|
test {
  let container : Container[Int, String] = { first: 1, second: "one" }
  inspect(container.first, content="1")
  inspect(container.second, content="one")
  inspect(transform(1, fn(x) { x.to_string() }), content="1")
}

或者如果你想使用相同的类型,移除重复的类型参数:

///|
priv struct Box[T] {
  value : T
}

///|
fn[A] identity(x : A) -> A {
  x
}

///|
test {
  let container : Box[Int] = { value: 1 }
  inspect(container.value, content="1")
  inspect(identity("value"), content="value")
}