【发布时间】:2015-08-28 10:42:08
【问题描述】:
我对 scalaz 还是很陌生,我正在尝试将各种类型转换为 monad 转换器。
我一直在尝试将Int 转换为OptionT[Future, Int],甚至转换为EitherT[Future, String, Int]。
我找到了一堆教程/SO 答案,它们解释了如何使用 point 执行此操作,但由于某种原因我无法编译它们。
比如这个来自here的sn-p:
1.point[({ type L[x] = EitherT[Future, String, x] })#L]
错误:(9, 9) 找不到
scalaz.Applicative[[x]scalaz.EitherT[scala.concurrent.Future,String,x]]类型的证据参数的隐式值
另一个来自Scalaz Monad Transformers
type Result[A] = OptionT[Future, A]
"".point[Result]
错误:(8, 10) 找不到
scalaz.Applicative[A$A35.this.Result]类型的证据参数的隐式值
我相信这个应该也可以,但是它说方法liftM不是Future[Int]的成员:
1.point[Future].liftM[OptionT] //doesnt compile
1.point[List].liftM[OptionT] //compiles
所有这些示例都失败了,但是如果我将Future 替换为List,它们就会编译。目前,这是对我有用的唯一方法,但有点冗长 - 我真的希望能够使用 point 代替:
OptionT(Future.successful(1.some))
为什么不编译?在最近的版本中,Future 的应用程序/monad 是否已从 scalaz 中删除?
我正在使用 scala 2.11.7 和 scalaz 7.1.3。对于它的价值,这些是我的进口:
import scala.concurrent.Future
import scalaz._
import Scalaz._
【问题讨论】: