In your example, the call to get[String]
is calling the get
method of StateFunctions
, reproduced here:
def get[S]: State[S, S] = init
Where State[S, A]
is an alias for StateT[Id, S, A]
which is an alias for IndexedStateT[Id, S, S, A]
.
Because you are using StateT
, you need to call get
on an instance of StateTMonadState[S, F]
, or StateTMonadState[String, Option]
in your case. The working example is:
import scalaz._
import Scalaz._
object StateTest {
type Pass[A] = StateT[Option, String, A]
val sm = StateT.stateTMonadState[String, Option]
def monadTest: Pass[String] =
for {
s <- sm.get
} yield s
}
The MonadState
instance can also be resolved implicitly via MonadState[F[_, _], S]
but it is less convenient to use due to the type lambda required. See MonadState.scala and StateT.scala for more info.