Created
July 31, 2014 21:50
-
-
Save louissalin/51109b416276fbb30507 to your computer and use it in GitHub Desktop.
Scala issue
This file contains hidden or 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
package test | |
case class Address(no: Int, street: String, city: String, state: String, zip: String) | |
trait LabelMaker[T] { | |
def toLabel(value: T): String | |
} | |
trait Plus[T] { | |
def plus(a1: T, a2: T): T | |
} | |
object LabelMaker { | |
implicit object AddressLabelMaker extends LabelMaker[Address] { | |
def toLabel(address: Address): String = { | |
import address._ | |
"%d %s, %s, %s - %s".format(no, street, city, state, zip) | |
} | |
} | |
} | |
object IntPluser { | |
implicit object IntPlus extends Plus[Int] { | |
def plus(a1: Int, a2: Int) = { | |
a1 + a2 | |
} | |
} | |
} | |
object StringPluser { | |
implicit object StringPlus extends Plus[String] { | |
def plus(a1: String, a2: String) = { | |
a1 + a2 | |
} | |
} | |
} | |
object Test { | |
def printLabel[T: LabelMaker](t: T) = implicitly[LabelMaker[T]].toLabel(t) | |
def plus[T: Plus](a1: T, a2: T) = implicitly[Plus[T]].plus(a1, a2) | |
} | |
//Test.printLabel(Address(100, "Monroe Street", "Denver", "CO", "80231")) --> works just fine | |
//Test.plus(1,2) --> fails! | |
// error: could not find implicit value for evidence parameter of type test.Plus[Int] | |
// Test.plus(2,3) | |
~ | |
~ | |
~ | |
~ | |
~ | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment