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
object ImplicitFunShowTest { | |
import Showing._ | |
def showList[T](list: List[T]) = list.map(t => show(t): String) | |
// no implicit argument of type Showing.Show[T] found for parameter x$0 of method apply in trait ImplicitFunction1 | |
def main(args: Array[String]): Unit = { | |
println( showList(List("a","b","c")) ) | |
println( showList(List(1,2,3)) ) | |
} | |
} |
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
scala> import scala.reflect.runtime.universe._ | |
import scala.reflect.runtime.universe._ | |
scala> class Bar { type T; def bar = weakTypeTag[T] } | |
defined class Bar | |
scala> object Barr extends Bar { type T = Int } | |
defined object Barr | |
scala> val tag = Barr.bar |
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
sealed trait FooImplicitScope | |
object FooImplicitScope { | |
implicit def Foo2String(f: Module.Foo): String = f.toString | |
implicit def Foo2Int(f: Module.Foo): Int = f.## | |
} | |
object Module { | |
private[Module] type A | |
type Foo <: A with FooImplicitScope | |
} |
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
import scala.language.experimental.macros | |
import scala.reflect.macros.whitebox.Context | |
trait HasCompanion[A] { | |
type Type | |
def companion: Type | |
} | |
object HasCompanion { | |
type Aux[A,C] = HasCompanion[A] { type Type = C } | |
def apply[A](implicit hc: HasCompanion[A]): hc.type = hc |
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
scala> object Module { | |
| type Foo[T] = Internal.Foo[T] | |
| object Foo { | |
| def pubMethod = "Hi!" | |
| } | |
| | |
| private[Module] object Internal { | |
| trait Foo[T] | |
| object Foo { | |
| implicit def FooString = new Foo[String] { |