summaryrefslogtreecommitdiff
path: root/test-nsc/files/pos/simplelists.scala
blob: 73b04a876255554869c9051e4e3bca954304ba78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    abstract class List[+a] {
      def head: a;
      def tail: List[a];
      def cons[b >: a](x: b): List[b] = new Cons[b, a](x, this);
    }

    object Nil extends List[All] {
      def error(msg: String): All = throw new java.lang.Error(msg);
      def head: All = error("Nil.head");
      def tail: List[All] = error("Nil.tail");
    }

    class Cons[c, d <: c](x: c, xs: List[d]) extends List[c] {
      def head: c = x;
      def tail: List[c] = xs;
    }