[英]Higher kinded type and Tagless final
I'm trying to write a function that can take any tagless final trait and return F[String]
. 我正在尝试编写一个可以采用任何无标记最终特征并返回F[String]
的函数。
def apply[Api[F[_]]](implementation: Api[F[_]]): F[String] = ???
I don't understand why the above is not compiling. 我不明白为什么上面没有编译。
The following works. 以下作品。
trait Api[F[_]]
def apply[F[_]](implementation: Api[F[_]]): F[String] = ???
But how can I get rid of this trait? 但是我如何摆脱这种特征?
Try 尝试
def apply[Api[_[_]], F[_]](implementation: Api[F]): F[String] = ???
When you write apply[Api[F[_]]](..)
you don't declare Api
and F
, you declare only Api
. 当您编写apply[Api[F[_]]](..)
您没有声明Api
和F
,而仅声明了Api
。 There F
doesn't matter, you can write apply[Api[F[_]]](..)
or apply[Api[G[_]]](..)
or just apply[Api[_[_]]](..)
, anyway you can't use F
outside. F
无关紧要,您可以编写apply[Api[F[_]]](..)
或apply[Api[G[_]]](..)
或仅apply[Api[_[_]]](..)
,无论如何都不能在外面使用F
Api[F[_]]
is correct syntax in declaration of type parameter, in type application in type position you should write Api[F]
. Api[F[_]]
是类型参数声明中的正确语法,在类型位置的类型应用程序中,应编写Api[F]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.