This file contains 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
class SuperA | |
def foo(): String | |
"SuperA#foo()" | |
end | |
end | |
class SuperB | |
def foo(): String | |
"SuperB#foo()" | |
end |
This file contains 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
case class Hoge() | |
case class Foo() | |
case class Dummy() | |
trait C[A, Conv] { | |
def method(a: A): Conv | |
} | |
trait Show[A] { def format(a: A): String } |
This file contains 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
case class X() { | |
// type T = String // この行を入れると何故かコンパイルを通る… | |
} | |
case class Y() | |
trait C[A] { | |
type T | |
} | |
trait Show[A] { def format(a: A): String } |
This file contains 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
// This file must be compiled under Scala 2.8.0 with -Xexperimental | |
case class Hoge() | |
case class Foo() | |
case class Dummy() | |
trait C[A] { | |
type Conv | |
def method(a: A): Conv | |
} |
This file contains 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
// It compiled under Scala 2.7.7.final. However, it doesn't compile under Scala 2.8.0.RC2. | |
import scala.collection.mutable.{Map} | |
object TypeInferenceFailure { | |
def f(x: Int) = x match { | |
case 0 => null.asInstanceOf[List[String]] | |
case _ => null.asInstanceOf[Map[Int, Int]] | |
} | |
} |
This file contains 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
/* | |
* This source-code is based on | |
* source-code on http://blog.srinivasan.biz/software/if-you-have-to-learn-just-one-programming-language | |
* Using foldLeft often simplifies functional codes. | |
*/ | |
/* | |
* Question: Do you want to play this game? | |
* You put down some money and roll a die between 1 and 100 | |
* Depending on your roll: | |
* 1-50: I keep your money. |
This file contains 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
object ImplicitRunnable { | |
//こっちのバージョンはまぎらわしいかも | |
//implicit def any2Runnable(block: => Any): Runnable = new Runnable { | |
// def run { block } | |
//} | |
implicit def fun2Runnable(block: () => Any): Runnable = new Runnable { | |
def run { block() } | |
} | |
def main(args: Array[String]) { | |
//使用例 |
This file contains 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
//This file should be compiled unser scala 2.8.0.RC2 with -P:continuations:enable | |
import scala.util.continuations._ | |
import scala.collection._ | |
trait Generator[+A] extends Traversable[A] { | |
def moveNext(): Boolean | |
def current: A | |
def foreach[U](f: A => U): Unit = { | |
while(moveNext()) { | |
f(current) |
This file contains 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
def sort(src: List[Int]): List[Int] = src match { | |
case (Nil|_::Nil) => src | |
case _ => | |
def merge(l: List[Int], r: List[Int]): List[Int] = (l, r) match { | |
case (Nil, ys) => ys | |
case (xs, Nil) => xs | |
case (x::xs, y::ys) => if(x < y) x::merge(xs, r) else y::merge(l, ys) | |
} | |
val (l, r) = src.splitAt(src.length / 2) | |
merge(sort(l), sort(r)) |
This file contains 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
object MyMain extends Application { | |
abstract sealed class Either[+A,+B] { | |
def map[C, D >: A](f:B => C) : Either[D,C] | |
def flatMap[C, D >: A](f:B => Either[D,C]) : Either[D,C] | |
} | |
case class Right[A,B](b:B) extends Either[A,B] { | |
def map[C, D >: A](f:B => C) = Right(f(b)) | |
def flatMap[C, D >: A](f:B => Either[D,C]) = f(b) | |
} | |
case class Left[A,B](a:A) extends Either[A,B] { |