Exhaustiveness mixing sealed type and enum

Remi Forax forax at univ-mlv.fr
Wed Jun 2 10:42:39 UTC 2021


Do we agree that the code below defines an exhaustive switch so no default is necessary ?

sealed interface List permits Cons, Nil { }
record Cons(String value, Object next) implements List { }
enum Nil implements List { NIL }

int size(List list) {
  return switch(list) {
    case Cons cons -> 1 + size(cons.next);
    case Nil.NIL -> 0
  };
}

regards,
Rémi


More information about the amber-spec-experts mailing list