Created
January 30, 2017 02:23
-
-
Save nafg/85699c49c1c0c30cc217e95a37577f27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait H { | |
def falsy: Boolean | |
} | |
case class A(b: Boolean) extends H { | |
override def falsy = !b | |
} | |
case class C(d: Byte, more: H) extends H { | |
override def falsy = d == 0 && more.falsy | |
} | |
case class E(f: A, g: C) | |
object Lesson5 { | |
def main(args: Array[String]): Unit = { | |
val a: A = A(true) | |
val h1: H = a | |
val h2: H = A(false) | |
val h3: H = C(17) | |
val h4: H = C(99) | |
println(h1) | |
println(h2) | |
println(h3) | |
println(h4) | |
def doSomethingWithAnH(h: H) = h match { | |
case A(b) => | |
} | |
} | |
val x: Any = "xx" | |
val y: Nothing = x | |
def m(letSay: Nothing): String = letSay | |
def n(s: String): Any = s | |
val z: Null = null | |
val zz: String = z | |
def falsyFunc(h: H): Boolean = h match { | |
case A(b) => !b | |
case C(d, more) => d == 0 && falsyFunc(more) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment