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 2.7 simple type constraint. This can only constrain a type parameter of this function. | |
// Below, in ListW.sumint28, we can't use this approach because we want to constrain T, | |
// a type param of the enclosing trait. | |
def sumint27A[T <: Int](l: List[T]) : Int = l.reduceLeft((a: Int, b: Int) => a + b) | |
trait IntLike[X] extends (X => Int) | |
object IntLike { | |
implicit val intIntLike: IntLike[Int] = new IntLike[Int] { def apply(x: Int) = identity(x) } | |
} |
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 A | |
class A2 extends A | |
class B | |
trait M[X] | |
// | |
// Upper Type Bound | |
// | |
def upperTypeBound[AA <: A](x: AA): A = x |
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 fails to compile with: | |
type mismatch; | |
found : Iterable[T] | |
required: CC[T] | |
else if (predicate(xs.head)) xs.drop(1) | |
^ | |
type mismatch; | |
found : Iterable[T] |
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.util.continuations._ | |
class Generator[A] extends Iterator[A] with (A => Unit @ suspendable) { | |
private var a: Option[A] = None | |
private var k: Option[Unit => Unit] = None | |
def next = { | |
val a0 = a.get | |
val k0 = k.get | |
a = None |
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
//scalac -P:continuations:enable | |
import scala.util.continuations._ | |
import scala.collection._ | |
object Generator { | |
type susp = cps[Any] | |
def make[A](body: (A => Unit @susp) => Unit @susp): Iterator[A] = new Iterator[A] { | |
val yields: A => Unit @susp = {v => | |
shift{k: (Unit => Any) => (k, v):Any } | |
} |
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
dir=`dirname $0` | |
stty -icanon min 1 -echo > /dev/null 2>&1 | |
java -Djline.terminal=jline.UnixTerminal -Xmx512M -jar `cygpath -w $dir`/sbt-launch-0.7.4.jar "$@" | |
stty icanon echo > /dev/null 2>&1 |
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
/** | |
* Part Zero : 10:15 Saturday Night | |
* | |
* (In which we will see how to let the type system help you handle failure)... | |
* | |
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0) | |
*/ | |
import scalaz._ | |
import Scalaz._ |
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
// Is this even faintly novel? The closest I've seen is | |
// | |
// http://stackoverflow.com/questions/2618891/using-lazy-evaluation-functions-in-varargs | |
// | |
// which is a bit clunky by comparison. But this is so trivial someone must have | |
// done it this way before. | |
// UPDATE: | |
// Thanks to the Twittersphere (@etorreborre, @pchiusano and @loverdos) for a few sightings of related things, | |
// |
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
#! /usr/bin/env bash | |
control_c() { | |
if $cygwin; then rm "$USERPROFILE"/play.boot.properties; fi | |
exit 1 | |
} | |
case "`uname`" in | |
CYGWIN*) cygwin=true;; | |
esac |
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 Config(host: String, port: Int) { | |
def prettyPrint(prefix: String, msg: String): String = | |
List(prefix, ": ", msg, " on ", host, ":", port.toString).mkString | |
} | |
/** | |
* Passing a configuration with implicits is like | |
* working in the state monad. You can "put" a | |
* new configuration even though we don't want that | |
* to happen in this particular example. We don't |
OlderNewer