Skip to content

Instantly share code, notes, and snippets.

View paulp's full-sized avatar
🤫

Paul Phillips paulp

🤫
  • CAZ, Inc.
  • Cascadia Autonomous Zone
View GitHub Profile
// Thanks for inferring types which I can't even access, scala.
scala> def f[A, CC[X]](xs: CC[A]) = xs
warning: there were 1 feature warning(s); re-run with -feature for details
f: [A, CC[X]](xs: CC[A])CC[A]
scala> f(scala.collection.immutable.BitSet(1))
res0: scala.collection.AbstractSet[Int] = BitSet(1)
scala> var x: scala.collection.AbstractSet[Int] = res0
<console>:9: error: class AbstractSet in package collection cannot be accessed in package collection
/** This should properly be a 'pos' test - all of it should compile.
* As usual it's in neg so as to alert the media if the behavior changes.
*/
package p1 {
trait Foo[+A]
trait Bar[+A] extends Foo[A]
class Good() extends Foo[Int] // directly inherits Foo[Int]
class Bad() extends Bar[Int] // indirectly inherits Foo[Int]
@paulp
paulp / blame-counts.txt
Created February 3, 2014 18:32
Number of lines in src/{library,reflect,compiler,repl} last touched by each person according to git blame.
65138 Paul Phillips
25821 Martin Odersky
19246 Eugene Burmako
15572 Aleksandar Prokopec
10850 Miguel Garcia
9197 Jason Zaugg
7652 Stéphane Micheloud
6952 Iulian Dragos
5807 Adriaan Moors
3367 Den Shabalin
[info] Compiling 10 Scala sources to /s/gll-combinators/target/scala-2.11.0-M8/test-classes...
[error] type mismatch;
[error] found : => Any
[error] required: AnyRef
[error] Note that <byname> extends Any, not AnyRef.
[error] Such types can participate in value classes, but instances
[error] cannot appear in singleton types or in reference comparisons.
[error] one error found
[error] (test:compile) Compilation failed
[error] Total time: 41 s, completed Feb 4, 2014 8:11:22 AM
"compute FIRST for binary alternatives" in check { (left: String, right: String) =>
import com.codecommit.util._
val leftFirst = if (left.length == 0) Set[Char]() else Set(left charAt 0)
val rightFirst = if (right.length == 0) Set[Char]() else Set(right charAt 0)
if (leftFirst.size == 0 || rightFirst.size == 0)
(left | right).first eq UniversalCharSet
else
(left | right).first == (leftFirst ++ rightFirst)
import com.codecommit.gll._
import org.specs2.ScalaCheck
import org.specs2.mutable._
trait Foo extends Specification with Parsers with ScalaCheck {
check { (left: String, right: String) =>
// import java.lang.String
if (false)
null == null
else
trait Foo
class Ev[T]
case class Bar[A](xs: Ev[A], f: A => Unit) extends Foo
object Test {
def main(args: Array[String]) {
val foo: Foo = new Bar(new Ev[Int], println(_: Int))
// This is disallowed.
// foo match { case x: Bar[a] => x.f(x.xs) }
@paulp
paulp / nbang.scala
Last active August 29, 2015 13:56
object Nats {
sealed trait Nat {
type Prev <: Nat { type Succ = Nat.this.type }
type Succ <: Nat { type Prev = Nat.this.type }
}
object Zero extends Nat
type _0 = Zero.type
type _1 = _0#Succ
type _2 = _1#Succ
// zip two lists, call map, function types inferred
scala> SafeList(1, 2, 3, 4) zip SafeList[Double](1, 2, 3, 4) map (_ + _)
res0: psp.core.Foreach[Double] = 2.0 :: 4.0 :: 6.0 :: 8.0 :: Nil
// zip three lists, call map, function types inferred
scala> SafeList(1, 2, 3, 4) zip SafeList[Double](1, 2, 3, 4) zip SafeList[Long](1, 2, 3, 4) map (_ + _ + _)
res1: psp.core.Foreach[Double] = 3.0 :: 6.0 :: 9.0 :: 12.0 :: Nil
package p {
trait N { type Name ; def make(): Name }
trait N1 extends N { class Name ; def make(): Name = new Name }
trait N2 extends N { class Name }
object g extends App with N1 with N2 {
val x = (this: N2).make()
// java.lang.ClassCastException: p.N1$Name cannot be cast to p.N2$Name
}
}