jarring type lambda

时间:2021-05-22 16:46:29

object IntStateMonad extends
Monad[({type IntState[A] = State[Int, A]})#IntState] {
...
}
This syntax can be a little jarring when you first see it. But all we are doing is
declaring an anonymous type within parentheses. This anonymous type has, as one
of its members, the type alias IntState , which looks just like before. Outside
the parentheses we are then accessing its IntState member with the # syntax.
Just like we can use a "dot" ( . ) to access a member of an object at the value level,
we can use the # symbol to access a type member ( See the "Type Member" section
of the Scala Language Specification ).