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
% Other listings-related settings from | |
% http://lampsvn.epfl.ch/trac/scala/export/26099/scala-tool-support/trunk/src/latex/scaladoc.sty | |
% activate the language and predefine settings | |
\lstset{ | |
language=Scala,% | |
xleftmargin=4mm,% | |
aboveskip=3mm,% | |
belowskip=3mm,% | |
fontadjust=true,% | |
columns=[c]fixed,% |
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
struct vec2; | |
struct vec3; | |
template<int I, int J> struct MagicVec2 | |
{ | |
friend struct vec2; | |
inline MagicVec2(vec3* _this); | |
inline vec2 operator=(const vec2& that); | |
inline vec2 operator=(const MagicVec2<I, J> &that); |
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
//Paste this code on a fresh Scala console. | |
trait Exp[+T] | |
case class Const[T](t: T) extends Exp[T] | |
implicit def toExp[T](t: T): Exp[T] = Const(t) | |
case class Plus(x: Exp[Int], y: Exp[Int]) extends Exp[Int] | |
class IntOps(x: Exp[Int]) { | |
def +(y: Exp[Int]) = Plus(x, y) | |
} |
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
//Much of the following code derives from scala.math.Ordering, | |
//and is released under the Scala LICENSE (http://www.scala-lang.org/node/146) | |
object BetterPartialOrdering { | |
trait PartialOrderingFromLteq[T] extends PartialOrdering[T] { | |
override def tryCompare(x: T, y: T): Option[Int] = | |
(lteq(x, y), lteq(y, x)) match { | |
case (true, false) => Some(-1) | |
case (false, true) => Some(1) | |
case (true, true) => Some(0) | |
case _ => None |
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 ivm._ | |
import expressiontree._ | |
import Lifting._ | |
import collection.generic.CanBuildFrom | |
import collection.TraversableLike | |
object OptimizationV1 { | |
val mergeMaps: PartialFunction[Exp[_], Exp[_]] = { | |
case MapNode(m@MapNode(coll, f), g) => |
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 scala.reflect.makro.Context | |
import language.experimental.macros | |
def macroId[A](c: Context)(v: c.Expr[A]): c.Expr[A] = c.reify(v.splice) | |
def id2[A](v: A) = macro macroId[A] | |
id2(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
$ ~/opt/scala-2.10.0-M6/bin/scalac -Xexperimental ./test-src/epfl/test4-functions/TestPatMat.scala | |
./test-src/epfl/test4-functions/TestPatMat.scala:63: error: type mismatch; | |
found : Prog.this.Rep[Prog.this.Rep[Int]] => Prog.this.M[String] | |
required: Prog.this.Rep[Int] => Prog.this.M[?] | |
def test = repInt(7) match { case 5 => "foo" case _ => "bar" } | |
^ | |
one error found |
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
//Paste this in the REPL | |
import language.implicitConversions | |
trait Exp[+T] | |
trait Def[+T] | |
case class Eq[T](a: Exp[T], b: Exp[T]) extends Def[T] | |
case class Const[T](t: T) extends Exp[T] | |
class Eq2[T](a: Exp[T], b: Exp[T]) extends Eq[T](a, b) with Exp[T] //This can be defined before or after f1 and f2, it makes no difference. |
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 Foo { | |
trait Exp[+T] | |
case class Const[+T](t: T) extends Exp[T] | |
implicit def fooPure[T](t: T): Exp[T] = Const(t) | |
class WithAsFoo[T](t: T) { | |
def asFoo(implicit conv: T => Exp[T]) = conv(t) | |
} | |
implicit def toWithAsFoo[T](t: T) = new WithAsFoo(t) | |
implicit def toMapSeq[T](e: Exp[Seq[T]]) = new MapSeq(e) |
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
+++ b/src/library/scala/Enumeration.scala | |
+ @deprecated("Names should be specified individually or discovered via reflection", "2.10.0") | |
+ def this(initial: Int, names: String*) = { | |
+ @deprecated("Names should be specified individually or discovered via reflection", "2.10.0") | |
def this(names: String*) = this(0, names: _*) | |
+++ b/src/library/scala/Predef.scala | |
+ // @deprecated("Use scala.AnyRef instead", "2.10.0") | |
+ // def AnyRef = scala.AnyRef |
OlderNewer