public class Int0Demo {

  sealed interface Int0 {}
  record Z() implements Int0 {}
  record NZ(int n) implements Int0 {}

  static Int0 add(Int0 n1, Int0 n2) {
    return switch (n1) {
      case Z() -> switch (n2) {
        case Z() -> new Z();
        case NZ(int b) -> new NZ(b);
      };
      case NZ(int a) -> switch (n2) {
        case Z() -> new NZ(a);
        case NZ(int b) -> new NZ(a + b);
      };
    };
  }

  static void check(Object actual, Object expected) {
    System.out.println((actual.equals(expected) ? "ok: " : "FAIL: ") + actual);
  }

  public static void main(String[] args) {
    check(add(new NZ(5), new NZ(3)), new NZ(8));
    check(add(new NZ(5), new Z()), new NZ(5));
    check(add(new Z(), new Z()), new Z());
    // check(add(new NZ(5), new NZ(-5)), new Z());
  }
}
