I am a little familiar with Haskell monad transformers, but new to Scalaz (version 7). I made (as I thought) a simple translation from the following Haskell code:
import Control.Monad.State
type Pass a = StateT String Maybe a
monadTest :: Pass String
monadTest = do
s <- get
return s
to this Scala code:
import scalaz._
import Scalaz._
object StateTest {
type Pass[A] = StateT[Option, String, A]
def monadTest: Pass[String] =
for {
s <- get[String]
} yield s
}
Haskell code compiles. Scala does not compile with the following error:
[error] .../StateTest.scala:9: type mismatch;
[error] found : scalaz.IndexedStateT[scalaz.Id.Id,String,String,String]
[error] required: StateTest.Pass[String]
[error] (which expands to) scalaz.IndexedStateT[Option,String,String,String]
[error] s <- get[String]
[error] ^
Firstly, it seems that scalaz implements StateTin terms IndexedStateT. OK. But it seems that monadic meaning get[String]has type StateT[Id, String, String]instead StateT[Option, String, String]. Why?
I am using Scala 2.10.1, scalaz 7.0.0.
source
share