Examples · learn/10-generics · 158 of 339
generic-type
Types can take parameters too.
tin run examples/learn/10-generics/generic-type.tin// Types can take parameters too. Option<T> and Result<T, E> are written this way.
type Pair<A, B> = { first: A, second: B }
fn swap<A, B>(p: Pair<A, B>): Pair<B, A> => Pair { first: p.second, second: p.first }
fn main() {
let p = Pair { first: 1, second: "one" }
print(p)
print(swap(p))
}