Skip to content

Instantly share code, notes, and snippets.

@einblicker
Created January 11, 2012 22:58
Show Gist options
  • Save einblicker/1597306 to your computer and use it in GitHub Desktop.
Save einblicker/1597306 to your computer and use it in GitHub Desktop.
sameLength(5)
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