Created
January 11, 2012 22:58
-
-
Save einblicker/1597306 to your computer and use it in GitHub Desktop.
sameLength(5)
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
class Vec(list: List[Double]) { | |
case class Value(list: List[Double]) | |
val value = Value(list) | |
def sameLength(x: Vec#Value): Option[Value] = { | |
if (x.list.length == list.length) Some(Value(x.list)) | |
else None | |
} | |
def innerProd(x: Value): Double = { | |
x.list.zip(value.list).map{case (a, b) => a*b}.sum | |
} | |
} | |
val v1 = new Vec(List(1,2,3)) | |
val v2 = new Vec(List(10,20,30)) | |
v1.innerProd(v2.value) | |
v1.innerProd(v1.sameLength(v2.value).get) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment