Skip to content

Instantly share code, notes, and snippets.

object DSL2 {
def main(args: Array[String]): Unit = {
val m1 = Machine(Agent("agent1"), null)
val m2 = Machine(Agent("agent2"), m1)
val m3 = Machine(Agent("agent3"), m2)
val selector = agent.compose(parent.compose(parent))
println("Name of agent: " + selector(m3).name)
println("Name of agent of m3: " + agent(m3).name)
import scala.xml.{Node, Elem, Group}
/**
* A path to a Node in a Node tree.
*/
sealed trait NodePath {
def depth: Int
}
object NodePath {
_SCRIPT_PATH="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
_SCRIPT_DIR=`dirname "${_SCRIPT_PATH}"}`
_EXTRADOC_HOME=${_SCRIPT_DIR}/..
export TOOL_CLASSPATH="${_EXTRADOC_HOME}/target/scala_2.8.0/classes:${_EXTRADOC_HOME}/src/main/resources"
export JAVA_OPTS="-Xms512M -Xmx2048M -Xss1M -XX:MaxPermSize=128M"
scala -classpath ${TOOL_CLASSPATH} com.novocode.extradoc.ExtraDoc "$@"
@szeiger
szeiger / gist:983883
Created May 20, 2011 21:39
Using the new higher-kinded collection magic in ScalaQuery
// A simple table with keys and values
val T = new Table[(Int, String)]("T") {
def k = column[Int]("KEY", O.PrimaryKey)
def v = column[String]("VALUE")
def * = k ~ v
}
// Create the table and insert some data
T.ddl.create
T.insertAll(1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "e")
@szeiger
szeiger / LiftFunction.scala
Created June 26, 2011 15:05
Lift a Scala function to a database function for H2, using Code.lift
package org.scalaquery.demo
import scala.reflect._
import org.scalaquery.ql._
import org.scalaquery.ql.extended.{ExtendedTable => Table}
import org.scalaquery.ql.extended.H2Driver.Implicit._
import org.scalaquery.simple.StaticQuery.updateNA
import org.scalaquery.session.Database
import org.scalaquery.session.Database.threadLocalSession
@szeiger
szeiger / ToTest.scala
Created November 18, 2011 14:22
Using an extra object to infer one of two type parameters of a method
object ToTest extends App {
val i1 = new Invoker(List(1,2,3,1))
val t1 = i1.to[Set]()
val t1t: Set[Int] = t1
println(t1)
val i2 = new Invoker(Seq("a","b"))
val t2 = i2.to[Array]()
val t2t: Array[String] = t2
@szeiger
szeiger / gist:1427411
Created December 3, 2011 15:44
HLTest.scala
package hltest
// Church Numerals
sealed trait Nat {
type Self <: Nat
type Apply[F[_], _]
type + [_ <: Nat] <: Nat
type * [_ <: Nat] <: Nat
type Flip_^ [_ <: Nat] <: Nat
@szeiger
szeiger / 1.scala
Created January 11, 2012 12:40
Compilation time affected hugely by type inference
sealed trait Nat {
type Self <: Nat
type + [_ <: Nat] <: Nat
type * [_ <: Nat] <: Nat
type Flip_^ [_ <: Nat] <: Nat
type ^ [T <: Nat] = T # Flip_^[Self]
type ++ = Succ[Self]
}
object Nat {
[info] Test run started
[info] Test run finished: 0 failed, 0 ignored, 0 total, 0.001s
[info] Passed: : Total 57, Failed 0, Errors 0, Passed 57, Skipped 0
trait Rep {
type Base
}
class Query[E] extends Rep { self =>
type C[_] <: Iterable[_]
type Base = C[E]
def map[F](f: E => F): Query[F] { type C[X] = self.C[X] } = ???
def to[D[_] <: Iterable[_]]: Query[E] { type C[X] = D[X] } = ???
}