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
package await | |
import java.util.concurrent.Callable | |
import java.util.concurrent.Executors | |
object BlockingDemo extends App { | |
val execSvc = Executors.newSingleThreadExecutor() | |
val worker = new MeaningOfLife() |
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 Poc2 { | |
trait TARInt | |
trait Basket[A,B] { | |
def iAmABasket = {} | |
} | |
trait BasketFactory[A,B] { | |
def create(v: A): Basket[A,B] |
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
// Compile with Scala 2.10+ or 2.9.1 with -Ydependent-method-types | |
class Ccy { | |
trait AbstractCurrency{ | |
type Currency <: AbstractCurrency | |
def value : Double | |
def make(d:Double) : Currency | |
def +(x: Currency): Currency = make(x.value + value) | |
} |
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 AllExamples extends App { | |
import shapeless._ | |
final class All[L <: HList](val values: L) { | |
def apply[A](implicit selector: Selector[L, A]): A = values.select[A] | |
} | |
object All { | |
// package a value of type A, convertible to type B, into an HList containing just B |
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> trait TF { | |
| type ![A] | |
| } | |
defined trait TF | |
scala> type Curried2[F[_, _]] = TF { | |
| type ![X] = TF { | |
| type ![Y] = F[X, Y] | |
| } | |
| } |
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
Answers http://stackoverflow.com/questions/10373318/mixing-in-a-trait-dynamically. | |
Compile as follows: | |
scalac Common_1.scala Macros_2.scala | |
scalac Common_1.scala Test_3.scala -cp <path to the result of the previous compilation> | |
Tested in 2.10.0-M3, will most likely not compile by the time 2.10.0 final is released, because we're actively rehashing the API. | |
However the principles will remain the same in the final release, so the concept itself is okay. | |
upd. Code updated for 2.10.0-M7. | |
upd. Code updated for 2.10.0-RC1. |
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> ListClass.info.members groupBy (_.associatedFile) foreach { case (k, vs) => println("%s\n %s\n".format(k, vs map (_.defString) mkString "\n ")) } | |
null | |
final def asInstanceOf[T0]: T0 | |
final def isInstanceOf[T0]: Boolean | |
final def !=(x$1: Any): Boolean | |
final def ==(x$1: Any): Boolean | |
/scala/trunk/build/pack/lib/scala-library.jar(scala/collection/GenTraversableLike.class) | |
final def isTraversableAgain: Boolean |
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 Alacarte { | |
trait Functor[F[_]]{ | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
trait Eval[F[_]] { | |
def F: Functor[F] | |
def evalAlgebra(fa: F[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
/* | |
THE OBJECTIVE: | |
Given some Q[A] (Q might be ScalaQuery's query, A might be the first column of the table), | |
there should be a function that can return an object that has a Q[B] (B might be the first two columns | |
of the table), and a way to go from a B to an A (e.g. from (Int, String) to Int). We need to have a | |
collection of such objects (not sure if List or HList). | |
The purpose is this: | |
Suppose for instance I want to develop a very pluggable issue tracker. Its core implementation might |
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 language.experimental.macros | |
import scala.reflect.makro.Context | |
object Name { | |
def nameplicitly[T](implicit t0: T): Name[T] = macro nameplicitly_impl[T] | |
def nameplicitly_impl[T : c.TypeTag](c: Context)(t0: c.Expr[T]): c.Expr[Name[T]] = | |
c.reify(new Name[T] { def t = t0.splice }) |