Created
December 19, 2016 18:23
-
-
Save rubenfiszel/aed8b23dbd3fa5ce921159fbcea04cb6 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
case class Lambda[A:Rep, B:Rep](f: A => B) extends (A => B) { | |
val rA = rep[A] | |
val rB = rep[B] | |
type InternalB = rB.Internal | |
lazy val lambda: Exp[rA.Internal => InternalB] = doLambdaDef(f)(rA, rB) | |
def apply(arg:A):B = { | |
implicit val mf = rB.m | |
val apply = Apply(lambda, rA.to(arg)) | |
rB.from(apply) | |
} | |
} | |
def sumIf(x: Lambda[T,Boolean] { type InternalB = scala.Boolean }): Int = { | |
val lambda: Exp[x.rA.Internal => scala.Boolean] = x.lambda | |
int(indexedSeq_sumIf(lambda)) | |
} | |
/* | |
[error] /home/atoll/lms-clean/src/main/scala/scala/lms/common/IndexedSeq.scala:52: type mismatch; | |
[error] found : IndexedSeqsExp.this.Exp[x.rA.Internal => x.InternalB] | |
[error] (which expands to) IndexedSeqsExp.this.Exp[x.rA.Internal => x.rB.Internal] | |
[error] required: IndexedSeqsExp.this.Exp[x.rA.Internal => Boolean] | |
[error] val lambda: Exp[x.rA.Internal => scala.Boolean] = x.lambda | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment