I want to call Scalaz's pure
method to put a value into the State monad. The following works:
type IntState[A] = State[Int, A]
val a = "a".pure[IntState]
a(1)
(Int, java.lang.String) = (1,a)
I can also eliminate the type alias (thanks Scalaz's Pure.scala):
val a = "a".pure[({type T[A]=State[Int,A]})#T]
a(1)
(Int, java.lang.String) = (1,a)
But that is extremely clunky. Is there a shorter way to synthesize a type like this? Like placeholder syntax for function literals, is there something like:
"a".pure[State[Int, *]]
For concise partial type application (arity-2) in Scala, you can infix type notation as followings.
Note that we can infix notation for two arity type constructor (or type alias).
Not sure if this qualifies as better, but here is one approach that @kmizu tweeted the other day:
You can make it look a little nicer by using symbolic type aliases.
the most popular way of reducing arity is kind-projector (https://github.com/non/kind-projector) plugin that is also used in cats library. By enabling this plugin your example can be transformed to:
Note: this syntax will be enabled in Dotty by default.