Skip to content

Instantly share code, notes, and snippets.

View Blaisorblade's full-sized avatar

Paolo G. Giarrusso Blaisorblade

View GitHub Profile
object experiment {
import language.experimental.macros
import language.dynamics
import scala.reflect.macros._
case class Rep[+T](x:String)
implicit def anyToRep[T](x:T) = new Rep[T](x.toString)
import language.postfixOps
import com.codecommit.gll._
object GLLBugReport extends RegexParsers {
def quote(s: Any) = "\"" + s + "\""
def showResults[R](s: Stream[Result[R]]) =
((s map {
case f @ Failure(a , b) => ("Failure", a, quote(b))
case s @ Success(a, b) => ("Success", quote(a), quote(b))
}) toList)
import annotation.tailrec
object TailRec {
// A tail-recursive function, from
// http://stackoverflow.com/a/6160080/53974
@tailrec def isDivis(x:Int, i:Int):Boolean =
if(i > 20) true
else if(x % i != 0) false
else isDivis(x, i+1)
@Blaisorblade
Blaisorblade / DeltaInt.hs
Last active December 18, 2015 03:18
Why does this not work?
{-# LANGUAGE TypeFamilies #-}
module DeltaInt where
class Changing a where
-- Using type families here is a bit convenient, but means risking trouble later.
type Delta a
nil :: a -> Delta a
apply :: a -> Delta a -> a
diff :: a -> a -> Delta a
/*
* Encode a pair of examples from GADT and OOP (Generalized Algebraic Data Types and Object Oriented Programming), OOPSLA '05.
*/
//Part of Fig. 11. This is not complete, as it looks rather boring.
//A universe construction, that is, a representation of types.
trait Rep[T] {
def eq(x: T, y: T): Boolean
@Blaisorblade
Blaisorblade / gist:5732172
Last active December 18, 2015 05:19
Agda example
module ListExamples where
open import Data.List
open import Relation.Binary.PropositionalEquality
open import Level
-- Declare a heterogeneous, typed list.
-- We use Γ for lists of types. Set is Agda's name for Type.
data MyList : List Set → Set₁ where
$ scalac -unchecked -Xprint:explicitouter,lambdalift,constructors BugOuterPart1.scala
[[syntax trees at end of explicitouter]] // BugOuterPart1.scala
package <empty> {
class Outer extends Object {
def <init>(): Outer = {
Outer.super.<init>();
()
};
final class Inner extends Object {
def <init>($outer: Outer.this.type): Outer.this.Inner = {
@Blaisorblade
Blaisorblade / MixinClashes.scala
Last active December 18, 2015 18:09
Test clashes with mixins
/**
* Here we create a diamond inheritance structure with trait Client at the
* bottom. Trait Client inherits the same member from two traits. What does
* Scalac do here?
*
* Answers:
*
* - If the two members are abstract and have the same signature, they are
* merged and the code is accepted (see helper).
* - If they have the same signature and both have bodies, the code is
@Blaisorblade
Blaisorblade / antZincSettings.sh
Last active December 18, 2015 18:19
Errors while building Scala with ant and zinc 0.2.5
jvm_opts='-Xms2048M -Xmx2048M -Xss1M -XX:MaxPermSize=256M -XX:+CMSClassUnloadingEnabled -XX:ReservedCodeCacheSize=64m -XX:+TieredCompilation -XX:+UseNUMA -XX:+UseParallelGC -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
@Blaisorblade
Blaisorblade / Foo.scala
Created July 26, 2013 13:59
An alternative desugaring for implicit case classes (kudos to @Toxaris!).
scala> :paste
// Entering paste mode (ctrl-D to finish)
class Foo(bar: Int)
implicit object Foo extends (Int => Foo) {
def apply(bar: Int) = new Foo(bar)
}
// Exiting paste mode, now interpreting.