Skip to content

Instantly share code, notes, and snippets.

View Blaisorblade's full-sized avatar

Paolo G. Giarrusso Blaisorblade

View GitHub Profile
@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
@Blaisorblade
Blaisorblade / Reduced.elf
Last active August 29, 2015 14:06
I'm confused by the lifetime of variables bound by Twelf's %solve, and documentation does not seem to help.
% (Possible) bug report or confusing behavior.
% The code is in three parts, Part 1 is boring and 3 are boring, the interaction
% between 2 and 3 is confusing. How long is the result of a %solve directive
% supposed to persist?
% I have an Agda background and I've read some papers on Twelf.
% I've seen this bug in Emacs, but I imagine this only requires keeping the
% Twelf server alive throughout.
@Blaisorblade
Blaisorblade / DeriveV2.scala
Last active August 29, 2015 14:06
Trying to implement a typed tree transform ([T]Exp[T] => Exp[∆[T]]) in Scala, where ∆[_] is a type function, with some successes
// Also at https://gist.github.com/Blaisorblade/1622b0809effb9a56061
package ilc
/**
* Incremental lambda calculus - an attempt at a *typed* Scala implementation.
* Should you want more details on the particular transform, see http://inc-lc.github.io/ and our
* PLDI paper at http://www.informatik.uni-marburg.de/~pgiarrusso/papers/pldi14-ilc-author-final.pdf
* — the transform is in Fig. 4(g).
*
* However, I **quickly** wrote a minimal introduction here so that you can make sense of the code.
@Blaisorblade
Blaisorblade / TryModule.scala
Last active August 29, 2015 14:08
A customizable implementation of Try (untested)
/* Based on code from the Scala standard library, hence covered by the Scala license. See https://github.com/scala/scala/blob/2.11.x/doc/LICENSE.md
* Copyright (c) 2002-2013 EPFL
* Copyright (c) 2011-2013 Typesafe, Inc.
*/
import scala.collection.Seq
import scala.util.control.NonFatal
import scala.language.implicitConversions
/*
@Blaisorblade
Blaisorblade / SMLModules.scala
Created January 18, 2015 16:16
Try encoding SML functors in Scala, v2
// A variant of https://gist.github.com/Blaisorblade/19ef1abb28e20995e187, answering
// 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) }