-1

i have a question about disjoint Matching pattern. The matching pattern is disjoint when each case does not step on other cases.

def func(list: List[Int]): Int = list match {
  case Nil => 0
  case x::t if (x < func(t)) => x
  case x::t => func(t)
}

My question: is "if" statement also counted to check if these cases disjoint is? so if we have a patching pattern like this it means the last case also include the second case and it would not be disjoint anyway . But if i change the last case to

case x::t if (x >= func(t)) => func(t)

would the matching pattern considered disjoint ?

Jeffrey Chung
  • 19,319
  • 8
  • 34
  • 54

1 Answers1

0

Since x < func(t) = !(x >= func(t)), yes, these patterns are all disjoint. The compiler doesn't use predicate disjointness in anyway; this will have no concrete implications.

OlivierBlanvillain
  • 7,701
  • 4
  • 32
  • 51