E4000#
Generic type variable name is already used.
Erroneous example#
///|
struct Container[T, T] {
value : T
}
///|
fn[A, A] transform(x : A) -> A {
x
}
Suggestion#
Use different names for type variables:
///|
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")
}
Or remove the duplicate type parameter if you meant to use the same type:
///|
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")
}