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
import scala.math | |
import scala.util.Random | |
/** | |
* Pricing a call option using a binomial option pricing model. | |
* Formulas from: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.119.9442&rep=rep1&type=pdf | |
*/ | |
val r = new Random |
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
scala> def foo[T : Manifest](a : List[T]) = { | |
| val m = implicitly[Manifest[T]] | |
| val I = classOf[Int] | |
| val S = classOf[String] | |
| m.erasure match { | |
| case I => "hi" | |
| case S => "bye" | |
| case _ => "whatever" | |
| } | |
| } |
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
//quick hack to pretty-print some text: | |
"((hi)(bye(yeah))((x)))".foldLeft(0){ | |
(a,b)=> { | |
var indent=a; | |
b match { | |
case '('=> println("("); indent=a+2; print(" "*indent); | |
case ')'=>println;indent=a-2;println(" "*indent + ")");print(" "*indent) | |
case x => print(x); |