File: t5578.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (39 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
trait Base {
  type Rep[T]
}

trait Expressions {
  // constants/symbols (atomic)
  abstract class Exp[T]
  // ...
  case class Sym[T](n: Int) extends Exp[T]

  // operations (composite, defined in subtraits)
  abstract class Def[T]

  // additional members for managing encountered definitions
  def findOrCreateDefinition[T](rhs: Def[T]): Sym[T]
  implicit def toExp[T:Manifest](d: Def[T]): Exp[T] = findOrCreateDefinition(d)
}

trait BaseExp extends Base with Expressions {
  type Rep[T] = Exp[T]

  def findOrCreateDefinition[T](rhs: Def[T]): Sym[T] = null // stub
}

trait NumericOps extends Base {
  def plus[T](x: Rep[T], y: Rep[T]): Rep[T]
}

trait NumericOpsExp extends BaseExp {
  case class Plus[T:Numeric](x: Rep[T], y: Rep[T])
    extends Def[T]

  def plus[T: Numeric](x: Rep[T], y: Rep[T]): Rep[T] = Plus[T](x,y)

  // Possible solutions:
// def plus[T: Numeric: Manifest](x: Rep[T], y: Rep[T]): Rep[T] = Plus[T](x, y)
// def plus[T](x: Rep[T], y: Rep[T])(implicit num: Numeric[T], man: Manifest[T]): Rep[T] = Plus(x,y)

}