Last active
April 16, 2017 16:24
-
-
Save chaomai/6844a4ad4ab26efa2014ada689c983ed to your computer and use it in GitHub Desktop.
This file contains 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 A(val value: Int) { | |
def +(b: Int): A = new A(value + b) | |
} | |
object A { | |
def >(a: Int): A = new A(a) | |
} | |
// ok | |
(A > 1 + 2 + 3).value |
This file contains 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 T | |
trait T1 extends T | |
trait T2 extends T | |
trait T3 extends T | |
trait Val[D]{ | |
def value:Int | |
} | |
object Val{ | |
def con[D](v:Int)=new Val[D] { | |
override def value = v | |
} | |
} | |
val v1 = Val.con[T1](1) | |
val v2 = Val.con[T2](2) | |
val v3 = Val.con[T3](3) | |
class B[S](val value: Int) { | |
def +[D](b: Val[D]): B[(S, D)] = new B[(S, D)](value + b.value) | |
} | |
object B { | |
def >[D](a: Val[D]): B[D] = new B[D](a.value) | |
} | |
// ok | |
(B > v1).value | |
// ok | |
((B > v1) + v2).value | |
// Error | |
(B > v1 + v2).value |
This file contains 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 SparseTensorFactory[Shape](sv: ShapeValue[Shape]) { | |
def *[D <: Dimension](dv: DimValue[D]): SparseTensorFactory[Shape ~ D] = | |
new SparseTensorFactory[Shape ~ D](sv.append(dv)) | |
def &(sc: SparkContext): SparseTensor[Shape] = | |
new SparseTensor[Shape](sc, sv) | |
} | |
object SparseTensorFactory { | |
def >[D <: Dimension](dv: DimValue[D]): SparseTensorFactory[RNil ~ D] = | |
new SparseTensorFactory[RNil ~ D](dv) | |
} | |
trait Dim1 extends VarDim | |
trait Dim2 extends VarDim | |
val dim1 = DimValue[Dim1](2) | |
val dim2 = DimValue[Dim2](3) | |
// Error:(36, 40) value * is not a member of org.chaomai.tensor.DimValue[Dim1] | |
val t = SparseTensorFactory > dim1 * dim2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment