Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala type alias naming rules?

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?

like image 722
pathikrit Avatar asked Jul 05 '26 06:07

pathikrit


1 Answers

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
like image 110
Erik Kaplun Avatar answered Jul 06 '26 20:07

Erik Kaplun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!