Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scala Native

yubessy
January 29, 2018

Scala Native

社内勉強会用資料です

yubessy

January 29, 2018
Tweet

More Decks by yubessy

Other Decks in Programming

Transcript

  1. $ sbt new scala-native/scala-native.g8 object Main { def main(args: Array[String]):

    Unit = println("Hello, world!") } $ sbt run Hello, World!
  2. (rec) def fib(n: Long): Long = n match { case

    0 => 0 case 1 => 1 case _ => fib(n - 2) + fib(n - 1) }
  3. (tail rec) def fibImpl(n: Long, a: Long, b: Long): Long

    = n match { case 0 => a case _ => fibImpl(n - 1, b, a + b) } def fib(n: Long): Long = { fibImpl(n, 0, 1) }
  4. (mut rec) def fib(n: Long): Long = n match {

    case 0 => 0 case _ => fibS(n - 1) } def fibS(n: Long): Long = n match { case 0 => 1 case _ => fib(n - 1) + fibS(n - 1) }
  5. (μs) rec tail rec mut rec JAR 74801223 262 67248872

    Native -O0 168336051 4 164421481 Native -O2 77311107 4 34026913 Native -O0 ( ) rec, mute rec JAR . tail rec Native -O2 ( ) mute rec JAR