Last active
January 27, 2017 13:14
-
-
Save pfcoperez/ab002db9f9dcd9f428f19f92f1da978e 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
abstract class FuncStackable { | |
def f(x: Int): Int | |
} | |
class Fidentity extends FuncStackable { | |
override def f(x: Int): Int = x | |
} | |
trait NInput extends FuncStackable { | |
val n: Int | |
abstract override def f(x: Int): Int = super.f(x*n) | |
} | |
val doublef = new Fidentity with NInput { val n: Int = 10 } | |
doublef.f(1) | |
///////////////////////////////////////// | |
abstract class IntCol { | |
def add(x: Int): Unit | |
def elements: Seq[Int] | |
} | |
class ListWrapper extends IntCol { | |
private var l: List[Int] = Nil | |
override def add(x: Int): Unit = l = x :: l | |
override def elements: Seq[Int] = l | |
} | |
trait Duplicate extends IntCol { | |
abstract override def add(x: Int): Unit = { | |
super.add(x) | |
super.add(x) | |
} | |
} | |
val duplicator = new ListWrapper with Duplicate | |
duplicator.add(1) | |
duplicator.elements | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment