simplelists.scala

来自「JAVA 语言的函数式编程扩展」· SCALA 代码 · 共 17 行

SCALA
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[Nothing] {  def error(msg: String): Nothing = throw new java.lang.Error(msg)  def head: Nothing = error("Nil.head")  def tail: List[Nothing] = 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}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?