using System; namespace dk.nsi.seal.FunctionalExt { public class DUnion { readonly A a; readonly B b; readonly uint tag; public DUnion(A v) { a = v; tag = 0; } public DUnion(B v) { b = v; tag = 1; } public R Match(Func f, Func g) { switch (tag) { case 0: return f(a); case 1: return g(b); default: throw new Exception("Unsupported tag: " + tag); } } public static implicit operator DUnion(A a) => new DUnion(a); public static implicit operator DUnion(B b) => new DUnion(b); } public class DUnion { readonly A a; readonly B b; readonly C c; readonly uint tag; public DUnion(A v) { a = v; tag = 0; } public DUnion(B v) { b = v; tag = 1; } public DUnion(C v) { c = v; tag = 2; } public R Match(Func f, Func g, Func h) { switch (tag) { case 0: return f(a); case 1: return g(b); case 2: return h(c); default: throw new Exception("Unsupported tag: " + tag); } } public static implicit operator DUnion(A a) => new DUnion(a); public static implicit operator DUnion(B b) => new DUnion(b); public static implicit operator DUnion(C c) => new DUnion(c); } }