--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Sun Jan 08 15:00:01 2012 -0500
@@ -0,0 +1,23 @@
+syntax: glob
+target/
+lib_managed/
+src_managed/
+lift_example/
+project/boot/
+.classpath
+.project
+.manager
+*~
+*.class
+*.log
+*\#
+src/main/scala.egp
+src/test/scala.egp
+sbt-launch*.jar
+.scala_dependencies
+*.orig
+.cache
+.settings
+.idea
+.idea_modules
+bin
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aRDF/project/build.scala Sun Jan 08 15:00:01 2012 -0500
@@ -0,0 +1,48 @@
+import sbt._
+import Keys._
+
+object BuildSettings {
+
+ val logger = ConsoleLogger()
+
+ val buildSettings = Defaults.defaultSettings ++ Seq (
+ organization := "org.w3",
+ version := "0.1",
+ scalaVersion := "2.9.1",
+ scalaHome := Some {
+ val bin = file("bin")
+ def latest = (bin.listFiles.toList filter { _.getName startsWith "scala-2.10.0.r" } sortWith { _.getName > _.getName }).headOption
+ latest match {
+ case Some(scala) => {
+ logger.info("found nightly build of scala compiler: %s" format scala.getName)
+ scala
+ }
+ case None => {
+ logger.info("downloading the latest scala compiler (nightly builds)")
+ val u = url("http://www.scala-lang.org/archives/downloads/distrib/files/nightly/distributions/scala-2.10.0.latest.zip")
+ val zip = file("/tmp/scala-latest.zip")
+ u #> zip !;
+ Process("unzip -o %s -d %s" format (zip.getAbsolutePath, bin.getAbsolutePath)) !;
+ latest getOrElse sys.error("couldn't download and set the latest scala compiler")
+ }
+ }
+ },
+ parallelExecution in Test := false,
+ scalacOptions ++= Seq("-deprecation", "-unchecked", "-Yvirtpatmat", "-optimize")
+ )
+
+}
+
+object YourProjectBuild extends Build {
+
+ import BuildSettings._
+
+ lazy val project = Project(
+ id = "aRDF",
+ base = file("."),
+ settings = buildSettings
+ )
+
+
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aRDF/sbt Sun Jan 08 15:00:01 2012 -0500
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+dir=$(dirname $0)
+cd "$dir"
+
+url="http://repo.typesafe.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.2/sbt-launch.jar"
+
+sbt="sbt-launch-0.11.2.jar"
+
+# set the right tool to download sbt
+if [ -n "$tool" ]; then
+ echo -n
+elif [ -n "$(which wget)" ]; then
+ tool="wget"
+elif [ -n "$(which curl)" ]; then
+ tool="curl"
+else
+ echo "Couldn't find a tool to download sbt. Please do the following"
+ echo "* download $url"
+ echo "* set the name of the file to $sbt"
+ echo "* relaunch ./sbt"
+ exit 1
+fi
+
+# download the sbt launcher if it's not already here
+if [ ! -f "$sbt" ]; then
+ case "$tool" in
+ "wget"*)
+ wget "$url" -O "./$sbt"
+ ;;
+ "curl"*)
+ curl "$url" -o "./$sbt"
+ ;;
+ *)
+ echo "don't know this tool: $tool"
+ exit 2
+ esac
+fi
+
+# tweak this line according to your needs
+java -Xmx512M -jar -Dfile.encoding=UTF8 -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m "$dir/$sbt" "$@"
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aRDF/src/main/scala/Main.scala Sun Jan 08 15:00:01 2012 -0500
@@ -0,0 +1,48 @@
+// afaik, the compiler doesn't not expose the unapply method
+// for a companion object
+trait Isomorphic[A, B] {
+ def apply(x: A): B
+ def unapply(x: B): Option[A]
+}
+
+// abstract module
+trait Module {
+ type X
+ type Y <: X
+ def X: Isomorphic[Int, X]
+ def Y: Isomorphic[X, Y]
+}
+
+// an implementation relying on case classes
+object ConcreteModule extends Module {
+ sealed trait X { def v: Int = 42 }
+ object X extends Isomorphic[Int, X] {
+ def apply(_v: Int): X = new X { }
+ def unapply(x: X): Option[Int] = Some(x.v)
+ }
+ case class Y(x: X) extends X
+ // I guess the compiler could do that for me
+ object Y extends Isomorphic[X, Y]
+}
+
+object Main {
+ def foo(t: Module)(x: t.X): Unit = {
+ import t._
+ x match {
+ case Y(_y) => println("y "+_y)
+ case X(_x) => println("x "+_x)
+ case x => println("___ + " + x)
+ }
+ }
+ def bar(t: Module): Unit = {
+ import t._
+ val x: X = X(42)
+ val y: Y = Y(x)
+ foo(t)(x)
+ foo(t)(y)
+ }
+ def main(args: Array[String]) = {
+ // call bar with the concrete module
+ bar(ConcreteModule)
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbt Sun Jan 08 15:00:01 2012 -0500
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+dir=$(dirname $0)
+cd "$dir"
+
+url="http://repo.typesafe.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.2/sbt-launch.jar"
+
+sbt="sbt-launch-0.11.2.jar"
+
+# set the right tool to download sbt
+if [ -n "$tool" ]; then
+ echo -n
+elif [ -n "$(which wget)" ]; then
+ tool="wget"
+elif [ -n "$(which curl)" ]; then
+ tool="curl"
+else
+ echo "Couldn't find a tool to download sbt. Please do the following"
+ echo "* download $url"
+ echo "* set the name of the file to $sbt"
+ echo "* relaunch ./sbt"
+ exit 1
+fi
+
+# download the sbt launcher if it's not already here
+if [ ! -f "$sbt" ]; then
+ case "$tool" in
+ "wget"*)
+ wget "$url" -O "./$sbt"
+ ;;
+ "curl"*)
+ curl "$url" -o "./$sbt"
+ ;;
+ *)
+ echo "don't know this tool: $tool"
+ exit 2
+ esac
+fi
+
+# tweak this line according to your needs
+java -Xmx512M -jar -Dfile.encoding=UTF8 -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m "$dir/$sbt" "$@"
+