159028 (1) [Avatar] Offline
#1
Hi,

I'm hoping someone could help me understand the pros and cons of the way some of the code in the book is written.

Often you see code like this:

trait TaxCalculation {
  type S <: TaxCalculationTable
  val table: S
}


What is the benefit of using a polymorphic type like this rather than writing:

trait TaxCalculation {
  val table: TaxCalculationTable
}


Or even:

trait TaxCalculation[S <: TaxCalculationTable] {
  val table: S
}


Similarly for function signatures:

def f[A <: Foo](a: A)


Versus:

def f(a: Foo)


Thanks for any insights,

Ashlin.
pschwarz (8) [Avatar] Offline
#2
+1 I have the same question

159028 wrote:Hi,

I'm hoping someone could help me understand the pros and cons of the way some of the code in the book is written.

Often you see code like this:

trait TaxCalculation {
  type S <: TaxCalculationTable
  val table: S
}


What is the benefit of using a polymorphic type like this rather than writing:

trait TaxCalculation {
  val table: TaxCalculationTable
}


Or even:

trait TaxCalculation[S <: TaxCalculationTable] {
  val table: S
}


Similarly for function signatures:

def f[A <: Foo](a: A)


Versus:

def f(a: Foo)


Thanks for any insights,

Ashlin.