Conditional Implicit Definitions Scala [duplicate]

你说的曾经没有我的故事 提交于 2020-05-17 05:51:10

问题


I have to solve this quinz but i can't find the correct answer.

trait Physics {
  implicit def air: Gaz,
  implicit def condense(implicit gaz: Gaz): Liquid,
  implicit def freeze(implicit liquid: Liquid): Solid

  implicitly[Solid]
}

Can you rewrite the last line with the inferred parameter explicitly written?

Hint: It should look like implicitly[Solid](...

Thank you so much!


回答1:


Here is a hint: first consider implicitly is just a method like any other

def implicitly[T](implicit e: T): T = e

Lets remove the keyword implicit such that

def implicitly[T](e: T): T = e

Given implicitly is just a method taking arguments, think about what would you have to do to make compiler happy and have method implicitly return a Solid?



来源:https://stackoverflow.com/questions/61170151/conditional-implicit-definitions-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!