What do <:<, <%<, and =:= mean in Scala 2.8, and where are they documented?

后端 未结 4 1619
野性不改
野性不改 2020-11-22 13:26

I can see in the API docs for Predef that they\'re subclasses of a generic function type (From) => To, but that\'s all it says. Um, what? Maybe there\'s documentation some

4条回答
  •  佛祖请我去吃肉
    2020-11-22 14:07

    Not a complete answer (others have already answered this), I just wanted to note the following, which maybe helps to understand the syntax better: The way you normally use these "operators", as for example in pelotom's example:

    def getStringLength(implicit evidence: A =:= String)
    

    makes use of Scala's alternative infix syntax for type operators.

    So, A =:= String is the same as =:=[A, String] (and =:= is just a class or trait with a fancy-looking name). Note that this syntax also works with "regular" classes, for example you can write:

    val a: Tuple2[Int, String] = (1, "one")
    

    like this:

    val a: Int Tuple2 String = (1, "one")
    

    It's similar to the two syntaxes for method calls, the "normal" with . and () and the operator syntax.

提交回复
热议问题