Skip to content

Instantly share code, notes, and snippets.

View Blaisorblade's full-sized avatar

Paolo G. Giarrusso Blaisorblade

View GitHub Profile
object api { class Universe { class Tree { type U = Universe.this.type; def toUTree(u: U): u.Tree = this } } }
def q(tree: api.Universe#Tree)(implicit u: tree.U): u.Tree = tree.toUTree(u)
def sameU(u: api.Universe)(t1: u.Tree, t2: u.Tree) = (t1, t2)
def sameU2(t1: api.Universe#Tree, t2: api.Universe#Tree)(implicit u: t1.U with t2.U): (u.Tree, u.Tree) = (t1.toUTree(u), t2.toUTree(u))
val (u1, u2) = (new api.Universe, new api.Universe)
val (t1, t2) = (new u1.Tree, new u2.Tree)
implicit val iu1: u1.type = u1
implicit val iu2: u2.type = u2
@Blaisorblade
Blaisorblade / build.sbt
Last active December 22, 2015 20:58
Example of my `autoAPIMappings` problems
scalaVersion := "2.10.2"
//scalacOptions := Seq("-deprecation", "-feature", "-Xlint")
//For Scaladoc, requires SBT 0.13. However, automatic mapping does not work for the standard library - for me at least.
autoAPIMappings := true
@Blaisorblade
Blaisorblade / JMMBarriers.scala
Last active December 23, 2015 00:09
JMM-safe implementation of memory barriers
object JMMBarriers {
@volatile private var volatile: Int = 0
/** Enforce a write barrier.
*
* Writes before this will not be reordered after this barrier, and will be
* visible from any other thread which performs a read barrier.
*/
def writeBarrier() { volatile = 1 }
/** Enforce a read barrier.
*
@Blaisorblade
Blaisorblade / _readme.md
Created September 18, 2013 18:59 — forked from shime/_readme.md

Having trouble installing the latest stable version of tmux?

Save yourself some time and run this little fellow!

Prerequisities

  • gcc
  • wget
@Blaisorblade
Blaisorblade / ScalacIsCrazy.scala
Created February 15, 2014 13:51
Scalac semi-gets type refinement with type functions, but only "semi" — see comments inside the gist for the breakage, comments below the gist for explanation.
package bugreport
object BugReport {
/* A simple universe of types */
sealed trait Type {
type Eval
type DT <: Type
}
sealed trait BaseType[BaseT] extends Type {
@Blaisorblade
Blaisorblade / TestDelayedInit.scala
Created February 19, 2014 15:46
Show that DelayedInit.delayedInit is called multiple times, once for each class in the hierarchy which inherits (directy or indirectly) from delayedInit.
class A extends DelayedInit {
def delayedInit(body: => Unit) {
println("delayedInit START")
body
println("delayedInit END")
}
println("A's constructor!")
}
class B extends A {
println("B's constructor!")
@Blaisorblade
Blaisorblade / SMLModules.scala
Last active August 29, 2015 14:06
Test encoding SML functors
// http://stackoverflow.com/a/23019436/53974
trait ORD {
type T
def leq(a: T, b: T): Boolean
}
// The most direct attempt runs into limitations of refinements.
//def F(X : ORD) = new { def eq(x : X.T, y : X.T) = X.leq(x, y) && X.leq(y, x) }
@Blaisorblade
Blaisorblade / scalacAntSettings.sh
Created September 14, 2014 13:02
Configuring ant to run Scalac tests
jvm_opts='-Xms2048M -Xmx2048M -Xss1M -XX:MaxPermSize=256M -XX:+CMSClassUnloadingEnabled -XX:ReservedCodeCacheSize=64m -XX:+TieredCompilation -XX:+UseNUMA -XX:+UseParallelGC'
export ZINC_OPTS="$jvm_opts"
export ANT_OPTS="$jvm_opts -Dpartest.java_opts='-Xmx256M -Xms32M -XX:MaxPermSize=128M'"
unset jvm_opts
-- Here I relate problem with unrealizable contexts in μDOT with known problems
-- in dependent type theory. I use Agda for illustration.
--
-- I also discuss the viewpoint given by denotational semantics.
module SoundnessOpenTermsXiRule where
open import Relation.Binary.PropositionalEquality
open import Data.Nat
open import Data.Bool
@Blaisorblade
Blaisorblade / VectorEqualityExtras.agda
Last active August 29, 2015 14:06
Show how to translate vector equality to "usual" equalities in different ways
-- Let's try to use the result of xs++[]=xs as an equality.
-- This problem was posted by Fuuzetsu on the #agda IRC channel.
module VectorEqualityExtras (A : Set) where
open import Relation.Binary.PropositionalEquality as P
open import Relation.Binary.HeterogeneousEquality as H using (_≅_; ≡-to-≅)
open import Function