When reading this article I came to the following syntax:
implicit val slaveCanRead: Slave HasPrivilege Read = null
The author says:
Also, please not that
Slave HasPrivilege Read
is just another notation forHasPrivilege[Slave, Read]
Keeping the example in basic scala, the example could also be
val foo: Map[String, Long] = Map()
val bar: String Map Long = Map()
I was looking for some documentation/articles that would explain this syntax but could not find any. Can someone point to the language feature which allows this syntax?
It’s really just as simple as T1 TCon T2 = TCon[T1, T2]
. It’s section 3.2.8 of the language specification.
InfixType ::= CompoundType {id [nl] CompoundType}
If the infix type ends with :
it is right associative, and otherwise it is left associative, just like methods, and mixing fixities is an error without parentheses.
This is an infix type. Thus
val map: Map[String, Int] = ...
is actually equivalent to
val map: String Map Int = ...
This is especially useful for the Function
type so you can write
val f: Int => Int = ...
instead of
val f: Function[Int, Int] = ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With