Aladdin - Scala Bugtracking
[#82] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Stephane Burak fixed 2003-08-07 13:30:13.0
subject scala.MatchError
code
object Main {

    def min0[A](less: (A, A) => Boolean, xs: List[A]): Option[A] = xs match {

        case List()  => None

        case List(x) => Some(x)  /*1*/
//      case x :: Nil => Some(x)  /*2*/
        case y :: ys => min0(less, ys) match {
            case Some(m) => if (less(y, m)) Some(y) else Some(m)

        }

    }

    def min(xs: List[Int]) = min0((x: Int, y: Int) => x < y, xs);

    def main(args: Array[String]) =
        System.out.println(min(List()));

}
what happened
Exception in thread "main" scala.MatchError:  in 'src/Main.scala' at line 4
what expected Example works fine if you replace line /*1*/ by line /*2*/. The value None should be printed out.
[back to overview]
Changes of this bug report
Burak  edited on  2003-08-27 18:13:38.0
matching empty sequences with empty patterns works now.
Burak  edited on  2003-08-27 18:13:55.0