Skip to content

Instantly share code, notes, and snippets.

View retronym's full-sized avatar

Jason Zaugg retronym

View GitHub Profile
@retronym
retronym / drop-to-repl-2.8.scala
Created January 30, 2010 17:12
Embedding REPL in 2.8 working around classpath propagation changes.
object IntepreterFix {
import scala.tools.nsc._
import Interpreter._
def break(args: DebugParam[_]*): Unit = {
val intLoop = new InterpreterLoop
intLoop.settings = {
val s = new Settings(Console.println)
// need to pass this explicitly to the settings for Scalac.
// See: http://old.nabble.com/-scala--recent-changes-in-2.8-nightly-classpath-management-td26233977.html
@retronym
retronym / numeric-woes.scala
Created February 6, 2010 11:01
Failed attempt to get rid of boilerplate in methods using Numeric[T]
// Sorry Predef, we want '+' back!
import Predef.{any2stringadd => _, _}
object test {
{
trait MyNumeric[T] extends Ordering[T] {
def plus(x: T, y: T): T
//
@retronym
retronym / collection-conversions-with-implicits.scala
Created February 14, 2010 12:02
Collection Conversions with ==>> implicit
trait ==>>[-A, +B] extends (A => B) {
self =>
def apply(a: A): B
def map[C](f: B => C) = new (A ==>> C) {
def apply(a: A) = f(self.apply(a))
}
def comap[C](f: C => A) = new (C ==>> B) {
def apply(c: C) = self.apply(f(c))
@retronym
retronym / pattern-matching-conjunction.scala
Created February 14, 2010 14:19
A combinator to allow pattern conjunctions
// Splitter to apply two pattern matches on the same scrutinee.
case object && {
def unapply[A](a: A) = Some((a, a))
}
// Extractor object matching first character.
object StartsWith {
def unapply(s: String) = s.headOption
}
//[[syntax trees at end of jvm]]// Scala source: conjunction.scala
package <empty> {
final class test extends java.lang.Object with ScalaObject {
final <synthetic> private[this] def gd1$1(x$1: Char): Boolean = scala.this.Predef.augmentString("aeiou").contains(scala.Char.box(x$1));
def this(): object test = {
test.super.this();
{
{
var temp2: java.lang.String("foo") = "foo";
{
@retronym
retronym / higher-order-unification.scala
Created February 22, 2010 08:47
A limitation of Scala 2.8's type constructor inference that could be solved by Higher Order Unification
object test {
trait Bar[M[_]]
def baz[M[_] : Bar, A](m: M[A]) = 0
implicit object ListBar extends Bar[List]
baz(List(1))
type EitherIntX[X] = Either[Int, X]
implicit object EitherIntXBar extends Bar[EitherIntX]
val e: Either[Int, String] = Left(1)
//baz(e)
@retronym
retronym / partial-function-return-inference.scala
Created March 6, 2010 21:20
Inferring the return type of a partial function
class PF[A] {
def apply[B](pf: PartialFunction[A, B]) = pf
}
def pf[A] = new PF[A]
pf[Any] { case 5 => true }
typed1():4030, Typers$Typer {scala.tools.nsc.typechecker}
this = {scala.tools.nsc.typechecker.Typers$NormalTyper@2012}
tree$4 = {scala.reflect.generic.Trees$Select@2128}"List[Option[Int]]().sequence"
mode$2 = 1
pt$2 = {scala.tools.nsc.symtab.Types$TypeRef$rawTypeRef$1@2137}"Option[List[Int]]"
sym$2 = {scala.tools.nsc.symtab.Symbols$NoSymbol$@2030}"<none>"
temp817 = {scala.reflect.generic.Trees$Select@2128}"List[Option[Int]]().sequence"
temp818 = {scala.reflect.generic.Trees$Apply@2140}"List[Option[Int]]()"
temp819 = {scala.tools.nsc.symtab.Names$TermName@2113}"sequence"
temp820 = null
import Predef.{doubleWrapper => _, _}
object test {
1.0: AnyRef
}
> ++ 2.8.0.Beta1
Getting Scala 2.8.0.Beta1 ...
:: retrieving :: org.scala-tools.sbt#boot-scala
confs: [default]
2 artifacts copied, 0 already retrieved (12552kB/1137ms)
[info] Building project bisect 1.0 against Scala 2.8.0.Beta1
[info]  using ScalazProject with sbt 0.7.1 and Scala 2.7.7
> ch  check-bytecode-action
[info]