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
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> class Prefix { class Dep { type P = Prefix.this.type } } | |
defined class Prefix | |
scala> val (p1, p2) = (new Prefix, new Prefix) | |
p1: Prefix = Prefix@2212c414 | |
p2: Prefix = Prefix@7e070e85 |
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
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import shapeless._ ; import SingletonTypes._ ; import Record._ | |
import shapeless._ | |
import SingletonTypes._ | |
import Record._ | |
scala> :paste |
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
module Reflect | |
import Decidable.Equality | |
using (xs : List a, ys : List a, G : List (List a)) | |
data Elem : a -> List a -> Type where | |
Stop : Elem x (x :: xs) | |
Pop : Elem x ys -> Elem x (y :: xs) |
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
22:06 ~/Projects/Kepler_5923/sandbox (ticket/5923)$ cat Macros.scala | |
import language.experimental.macros | |
import scala.reflect.macros.Context | |
trait Iso[T, U] { | |
def to(t : T) : U | |
// def from(u : U) : T | |
} | |
object Iso { |
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 idioms._ // http://github.com/aztek/scala-idioms | |
trait Cell[T] { | |
def ! : T | |
def := (value: T) { throw new UnsupportedOperationException } | |
} | |
val frp = new Idiom[Cell] { | |
def pure[A](a: ⇒ A) = new Cell[A] { | |
private var value = a |
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> class Bippy(xs: List[Int]) extends improving.TypesafeProxy(xs) { def isEmpty = true } | |
defined class Bippy | |
scala> val bippy = new Bippy(1 to 10 toList) | |
bippy: Bippy = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) | |
scala> bippy.slice(3, 7) | |
[proxy] $line4.$read.$iw.$iw.bippy.slice(3, 7) | |
res1: List[Int] = List(4, 5, 6, 7) |
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.language.experimental.macros | |
import scala.reflect.macros.Context | |
import shapeless._ | |
object NatExample { | |
def toNat(n: Int): Any = macro toNat_impl | |
def toNat_impl(c: Context)(n: c.Expr[Int]) = { | |
import c.universe._ |
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 scalaz._ | |
import scalaz.std.option._ | |
import scalaz.syntax.functor._ | |
trait Inc extends (Int => Int) { | |
implicit def incToLiftable(i: this.type): { | |
def lift(implicit F: Functor[Option]): Option[Int] => Option[Int] | |
} = implicitly[this.type => LiftV[Option, Int, Int]].apply(i) | |
def apply(x: Int) = x + 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
/** | |
* 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
import shapeless._ | |
trait Flatten[I, O <: HList] { | |
def apply(i: I): O | |
} | |
trait FlattenLow { | |
implicit def otherFlatten[I] = new Flatten[I, I :: HNil] { | |
def apply(i: I) = i :: HNil | |
} |