Question

I tried to do a Google search but I failed to find anything relevant because of the symbology involved.

I know this compiles type ==>[A, B] = Map[A, B] but this does not type m==>[A, B] = Map[A, B]. Also, this does not compile type =m=>[A, B] = Map[A, B].

Also, I know that these are equivalent def foo: Int ==> String = ??? and def foo: ==>[Int, String] = ???. But I could not find any official documentation where these rules are specified? Where is it specified that I can subsitute the 2 type params to be on either side of the type alias? What if I had 3 type parameters? If I have this: type ==>[A, B, C], how can I do something like def foo: A ==> B ==> C?

Était-ce utile?

La solution

Scala identifier names cannot contain a mix of symbols and characters. This applies uniformly on method as well as type and type constructor names.

scala> type =m=>[A, B] = Map[A, B]
<console>:1: error: identifier expected but '=' found.
       type =m=>[A, B] = Map[A, B]
            ^

scala> type ===>[A, B] = Map[A, B]
defined type alias $eq$eq$eq$greater

scala> type mmmm[A, B] = Map[A, B]
defined type alias mmmm

compare with:

scala> def foo = 3
foo: Int

scala> def === = 3
$eq$eq$eq: Int

scala> def =foo= = 3
<console>:1: error: identifier expected but '=' found.
       def =foo= = 3
           ^

The only exception is foo_<symbol-here> but which will not help you name something =m=>.

scala> def foo_? = 3
foo_$qmark: Int

scala> def foo_* = 3
foo_$times: Int

scala> def foo_==> = 3
foo_$eq$eq$greater: Int
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top