Xen / examples v0.1.0-demo.2
Reuse with different types
This topic is not available in the selected language or version. Showing the start of this section.
Reuse with different types
Run from the repository or distribution root. Put xen on PATH, or substitute ./bin/xen.
xen check examples/generics.xenxen run examples/generics.xenExpected output
Section titled “Expected output”7helloComplete source
Section titled “Complete source”// SPDX-License-Identifier: MIT OR Apache-2.0struct Pair<T> { first: T, second: T }
fn identity<T>(value: T) -> T { return value;}
fn main() { let pair = Pair<Int> { first: identity(7), second: 9 }; println(pair.first); println(identity<String>("hello"));}Build an executable
Section titled “Build an executable”xen build examples/generics.xen -o appRun the generated executable on a compatible Linux machine.