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
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
/* | |
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 }) |
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 shapeless | |
import shapeless._ | |
import HList._ | |
package object autoordering extends App { | |
type Iso[T, L <: HList] = HListIso[T, L] | |
implicit def ccOrdering[C, L <: HList](implicit iso: Iso[C, L], L: Ordering[L]) = new Ordering[C] { |
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
/** | |
* Digging through arbitrarily nested case classes, tuples, and lists | |
* by Travis Brown | |
* | |
* In response to this question by Channing Walton on the Shapeless dev list: | |
* | |
* https://groups.google.com/d/msg/shapeless-dev/hn7_U21tupI/Zm9h3uNb51gJ | |
* | |
* Tested with Scala 2.9.2 and Shapeless 1.2.3. Should work on 1.2.2 with minor edits. | |
*/ |
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
// Searching for large ModAux instances can be extremely slow. | |
// See this version for a faster solution: https://gist.github.com/4108026 | |
import shapeless._, Nat._ | |
trait FizzBuzz[N <: Nat] { | |
def steps: List[String] | |
def show = println(steps.reverse.mkString("\n")) | |
} |
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
19:07 ~/Projects/Kepler_typemacros/sandbox (topic/typemacros)$ scalac Macros.scala | |
19:07 ~/Projects/Kepler_typemacros/sandbox (topic/typemacros)$ scala -cp . | |
Welcome to Scala version 2.10.1-20121120-175733-b60f5bcf2c (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> class C extends AnyRef with Macros.Foo[Int]("2") | |
defined class C | |
scala> new C().hello |