This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |