Scala unexpectedly compiles a file, are there implicit conversions at work? -


i trying figure out why classes below compile without error in scala. expect createtestclass method in dotest class fail typing error because tries supply implicit parameter has type typeclass[a], instead of such instance, provides lambda type a => string.

is there implicit conversion @ work here? how go figuring out what's going on?

object test {    trait typeclass[a] {     def asstring(a: a): string   }    object typeclass {     def apply[a: typeclass]: typeclass[a] = implicitly[typeclass[a]]   }    case class testclass[a: typeclass](foo: option[a] = none)    object testclass {     def apply[a: typeclass]: testclass[a] = testclass[a]()   }  }  object dotest {   import test.testclass    def createtestclass[a]: testclass[a] =     testclass.apply[a]((_: a) => "test")  } 

scala 2.12 introduced new feature: lambda syntax sam (single abstract method) types. that's you're seeing here.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -