fn identity(x: T): T = x type Pair = | MkPair(A, B) fn first(p: Pair): A = match p { MkPair(a, _) => a, } fn second(p: Pair): B = match p { MkPair(_, b) => b, } fn mapOption(opt: Option, f: fn(T): U): Option = match opt { None => None, Some(x) => Some(f(x)), } fn double(x: Int): Int = x * 2 let id_int = identity(42) let id_str = identity("hello") let pair = MkPair(1, "one") let fst = first(pair) let snd = second(pair) let doubled = mapOption(Some(21), double) fn showOption(opt: Option): String = match opt { None => "None", Some(x) => "Some(" + toString(x) + ")", } fn printResults(): Unit with {Console} = { Console.print("identity(42) = " + toString(id_int)) Console.print("identity(\"hello\") = " + id_str) Console.print("first(MkPair(1, \"one\")) = " + toString(fst)) Console.print("second(MkPair(1, \"one\")) = " + snd) Console.print("map(Some(21), double) = " + showOption(doubled)) } let output = run printResults() with {}