This file contains hidden or 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 UnitsTest extends App { | |
import Units._ | |
val length1 = m(23) | |
val length2 = m(17) | |
val area: Area = length1 * length2 // Works, Quantity[_2, _0] | |
val time = s(42) | |
// Just to show that mixing units works... | |
val foo: Foo = time * length1 // Works, Quantity[_1, _1] |
This file contains hidden or 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 UnitsTest extends App { | |
import Units._ | |
import Integers._ | |
val length1 = m(23) | |
val length2 = m(17) | |
val area: Quantity[_2, _0] = length1 * length2 // Works | |
val time = s(42) | |
val foo: Quantity[_1, _1] = time * length1 // Works |
This file contains hidden or 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 UnitExample2 extends App { | |
val mass: Mass[Double] = 4.0 kg | |
val longMass: Mass[Long] = (4.0 kg) asLong | |
val length: Length[Int] = (5 m) | |
val time = 1 s | |
val time2: Time[Int] = time + time | |
val time3 = time2 + (1 minute) | |
val temperature: Temperature[BigDecimal] = BigDecimal("22.22") k | |
val speed: Speed[Int] = length / time | |
val area: Area[Int] = length * length |
This file contains hidden or 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
case class Quantity[M <: MInt, KG <: MInt, S <: MInt, A <: MInt, K <: MInt, Mol <: MInt, CD <: MInt, T: Numeric](value: T) { | |
def asInt = Quantity[M, KG, S, A, K, Mol, CD, Int](numeric[T].toType[Int](value)) | |
def asLong = Quantity[M, KG, S, A, K, Mol, CD, Long](numeric[T].toType[Long](value)) | |
def asFloat = Quantity[M, KG, S, A, K, Mol, CD, Float](numeric[T].toType[Float](value)) | |
def asDouble = Quantity[M, KG, S, A, K, Mol, CD, Double](numeric[T].toType[Double](value)) | |
def toInt: Int = (numeric[T].toType[Int](value)) | |
def toLong: Long = (numeric[T].toType[Long](value)) | |
def toFloat: Float = (numeric[T].toType[Float](value)) |
This file contains hidden or 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
name := "usagecounter" | |
version := "0.9" | |
scalaVersion := "2.10.0-SNAPSHOT" | |
libraryDependencies += "org.scala-lang" % "scala-compiler" % "2.10.0-SNAPSHOT" | |
resolvers += "Scala-Tools Maven2 Snapshots Repository" at "http://scala-tools.org/repo-snapshots" |
This file contains hidden or 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
// Example: new int[]{Integer.MAX_VALUE, 1} should be treated as one large, unsigned number and print: 8589934590 (So basically 2³³). | |
def toSimpleString(num: Array[Int]) = { | |
val iArr = num.clone | |
val s = new Array[Char](iArr.length * 10) | |
var i = s.length - 1 | |
var div = 0L | |
while (i >= 0) { | |
s(i) = ('0' + (iArr(i) % 10).toChar).toChar | |
div = (iArr(i) / 10) |
This file contains hidden or 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
trait Eq[-T] | |
def equal[T](left : T, right : T)(implicit eqT : Eq[T]) = true | |
implicit def eqInt = new Eq[Int]{} | |
trait List[T] | |
implicit def eqList[T](implicit eqT : Eq[T]) = new Eq[List[T]] {} |
This file contains hidden or 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
trait Eq[-T] | |
def equal[T](left : T, right : T)(implicit eqT : Eq[T]) = true | |
implicit def eqInt = new Eq[Int]{} | |
trait List[T] | |
implicit def eqList[T](implicit eqT : Eq[T]) = new Eq[List[T]] {} |
This file contains hidden or 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
ANT_OPTS="-Xms512M -Xmx2048M -Xss1M -XX:MaxPermSize=256M" ant build | |
Buildfile: /home/soc/Entwicklung/scala/build.xml | |
init.starr: | |
init: | |
[echo] build time: 28 January 2012, 16:35:29 | |
[echo] java version: OpenJDK 64-Bit Server VM 1.7.0_147-icedtea | |
[echo] java args: -Xms512M -Xmx2048M -Xss1M -XX:MaxPermSize=256M | |
[echo] javac args: |
This file contains hidden or 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
ant libs.llvm | |
Buildfile: /home/soc/Entwicklung/scala/build.xml | |
libs.start: | |
libs.pre-llvm: | |
libs.llvm: | |
[mkdir] Created dir: /home/soc/Entwicklung/scala/build/libs/classes/llvm |