Skip to content

Instantly share code, notes, and snippets.

@adriaanm
adriaanm / vpm_opt_bench.scala
Created November 28, 2011 16:08
virtpatmat compilation of a match and various hand-coded optimizations
import improving.benchmark.Benchmark.Race
val list = List(1, 3, 4, 7)
val race = Race(() => fastMatch(list), () => virtMatch_no_option(list))(100000).converge()
def fastMatch(x1: List[Int]) = {
x1 match {
case 1 :: 3 :: 4 :: 5 :: x => println("nope")
case 1 :: 3 :: 4 :: 6 :: x => println("nope") // only need to test whether the previous case failed due to the third element not being 5, and whether third element is 6
@adriaanm
adriaanm / gist:1446946
Created December 8, 2011 13:06
verifyerror
[adriaan@lampmac13 scala (topic/virtpatmat)]$ qsc -Yvirtpatmat -Xprint:typer test/files/run/virtpatmat_alts.scala
sharedPrefix: List()
collapsedTreeMakers: List(AlternativesTreeMaker(value x1,List(if (x1.ne(null))
if (true.==(x1._1))
{
val x4: Boolean = x1._1;
if (true.==(x1._2))
{
val x5: Boolean = x1._2;
scala.this.Some[(Boolean, Boolean)](x1)
@adriaanm
adriaanm / virtpatmat_skolems.scala
Created February 23, 2012 14:43
breaking virtpatmat with skolems
// exploring skolems/existentials that stem from scrutinee.tpe/unapply-type-params,
// and how they break virtpatmat
object Test {
object UnBounded {
def unapply[A](xs: UnBounded[A]): Option[A] = Some(xs.el)
}
class UnBounded[T](val el: T)
object Bounded {
def unapply[A <: Ord[A]](xs: Bounded[A]): Option[A] = Some(xs.el)
@adriaanm
adriaanm / virtpatmat_scala.scala
Created February 24, 2012 11:03
Introducing virtpatmat
trait VirtualizeMatch {
type Pure[T] = T
type Monad[T] = Option[T]
object __match {
def zero: Monad[Nothing] = None
def one[T](x: Pure[T]): Monad[T] = Some(x)
def guard[T](cond: Pure[Boolean], then: => Pure[T]): Monad[T] = if(cond) Some(then) else None
def runOrElse[T, U](in: Pure[T])(matcher: Pure[T] => Monad[U]): Pure[U] = matcher(in) getOrElse (throw new MatchError(in))
def isSuccess[T, U](x: Pure[T])(f: Pure[T] => Monad[U]): Pure[Boolean] = !f(x).isEmpty
@adriaanm
adriaanm / patmat_gadt.scala
Created February 27, 2012 17:05
why the old GADT typing rules are wrong
class TestPos2 {
class Base[+T]
case class C[T](x: T) extends Base[T]
def foo[T](b: Base[T]): T =
b match {
case C(x) =>
// since b: Base[T] and Base is covariant in T, b: Base[X forSome {type X <: T}], where we may assume Base to be invariant in its first type parameter
// thus, since b is actually a C[U], we may assume that U =:= X forSome {type X <: T}
// hence, x: X forSome {type X <: T}, or, by subsumption, x: T
x
@adriaanm
adriaanm / fb_delete_allgroupmembers.js
Created March 2, 2012 23:55
delete all members of a fb group -- c'mon facebook, how hard can it be?
// first go to https://www.facebook.com/groups/XXXX/members/
// then paste this in the javascript console
deleteAll = [];
deleteAll.elms = [];
deleteAll.canClick = function (el) {
return (typeof el != 'undefined') && (typeof el.click != 'undefined');
}
deleteAll.load = function() {
[push]
default = tracking
[clean]
requireForce = false
[grep]
lineNumber = true
extendedRegexp = true
[log]
# relative, local, default, iso, rfc, and short
date = relative
Buildfile: /Users/adriaan/git/scala-build/build.xml
init.jars.check:
init.jars:
[echo] Updating bootstrap libs. (To do this by hand, run ./pull-binary-libs.sh)
[exec] Resolving [943cd5c8802b2a3a64a010efb86ec19bac142e40/lib/ant/ant-contrib.jar]
[exec] Resolving [3fc1e35ca8c991fc3488548f7a276bd9053c179d/lib/ant/ant-dotnet-1.0.jar]
[exec] Resolving [7b456ca6b93900f96e58cc8371f03d90a9c1c8d1/lib/ant/ant.jar]
[exec] Resolving [7e50e3e227d834695f1e0bf018a7326e06ee4c86/lib/ant/maven-ant-tasks-2.1.1.jar]

Scala Project & Developer Guidelines

These guidelines are meant to be a living document that should be changed and adapted as needed. We encourage changes that make it easier to achieve our goals in an efficient way.

General Workflow

This is the process for committing code to the Scala project. There are of course exceptions to these rules, for example minor changes to comments and documentation, fixing a broken build etc.

  1. Make sure you have signed the Scala CLA, if not, sign it.
  2. Before starting to work on a feature or a fix, it's good practice to ensure that:
@adriaanm
adriaanm / eclipsify_sbt.sh
Created October 19, 2012 00:36
rewire sbt's directory structure so it adheres to a standard eclipse can deal with
#!/bin/sh
BASE=$HOME/git/xsbt/
for SRC in `find $BASE -not -path '*/src*/*' -name '*.scala'`;do
PKG=`grep "^\s*package " $SRC | perl -pse 's/\s*package\s*(\w*?)\b/package $1/' | tr -d '\r' | tr -d ';' | cut -d' ' -f2 | tr '\n.' '//'`
mkdir -p `dirname $SRC`/src/main/scala/$PKG
ln -s $SRC `dirname $SRC`/src/main/scala/$PKG`basename $SRC`
done