Scala 猫的拟像中的@noop是什么
什么是猫的@noop注释。基本上,它不接受任何像@op这样的字符串别名。这是它的scala文档Scala 猫的拟像中的@noop是什么,scala,scala-cats,Scala,Scala Cats,什么是猫的@noop注释。基本上,它不接受任何像@op这样的字符串别名。这是它的scala文档 /** * Annotation that may be applied to methods on a type that is annotated with `@typeclass`. * * Doing so results in the method being excluded from the generated syntax ops type. */ class noop() e
/**
* Annotation that may be applied to methods on a type that is annotated with `@typeclass`.
*
* Doing so results in the method being excluded from the generated syntax ops type.
*/
class noop() extends StaticAnnotation
我对这个文档感到困惑。有人能给我解释一下,并给我一个如何使用它的例子吗
事先非常感谢所以让我们假设您有这个typeclass:
@typeclass trait Foo[A] {
def bar(x: A)(y: A): A
}
然后,您将能够(通过Simularum定义的隐式语法)编写此方法:
def baz[A: Foo](x: A, y: A): A = x bar y
如果您改为使用@noop
注释bar
方法,则上面不会编译为“bar不是类型a的成员”,因为不会提供从a到具有bar方法的对象的隐式转换