Skip to content

Instantly share code, notes, and snippets.

@rubenfiszel
Last active November 24, 2016 23:17
Show Gist options
  • Save rubenfiszel/8d7f2b2c5c87e4349c187ab38a0e97ef to your computer and use it in GitHub Desktop.
Save rubenfiszel/8d7f2b2c5c87e4349c187ab38a0e97ef to your computer and use it in GitHub Desktop.
package scala.lms
package common
import simulacrum._
trait Ints2 extends Base {
@typeclass trait Num[A]{
@op("+") def plus(x:A, y: A): A
}
@typeclass trait IntOps[A] extends Num[A]{
def plus(x:A, y: A): A
@op("-") def minus(x:A, y: A): A
}
type Int
implicit def intBaseOps: IntOps[scala.Int]
implicit def intStagedOps: IntOps[Int]
implicit def intRep: Rep[Int] { type Internal = scala.Int }
implicit def intLift: Lift[scala.Int,Int]
}
trait Ints2Impl extends Ints2 with BaseExp {
case class Plus(e1: Exp[scala.Int], e2: Exp[scala.Int]) extends Def[scala.Int]
case class Minus(e1: Exp[scala.Int], e2: Exp[scala.Int]) extends Def[scala.Int]
case class Int(e: Exp[scala.Int]) extends Expressable[scala.Int]
val intBaseOps: IntOps[scala.Int] = new IntOps[scala.Int] {
def plus(x:scala.Int, y:scala.Int) = x + y
def minus(x:scala.Int, y:scala.Int) = x - y
}
val intStagedOps: IntOps[Int] = new IntOps[Int] {
def plus(x:Int, y:Int) = Int(Plus(x.e, y.e))
def minus(x:Int, y:Int) = Int(Minus(x.e, y.e))
}
private val repE = RepE[scala.Int, Int](Int)
val intRep: Rep[Int] { type Internal = scala.Int } = repE
val intLift: Lift[scala.Int,Int] = repE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment