2015-08-28 58 views
0

我是很新,scalaz创建OptionT [未来,A],而我试图找出转换不同类型单子变压器。从较低kinded型

我一直在试图将Int转换为OptionT[Future, Int],甚至转换为EitherT[Future, String, Int]

我发现了一堆教程/ SO解释如何使用point做到这一点的答案,但由于某种原因,我不能编译它们。

例如,该段从here

1.point[({ type L[x] = EitherT[Future, String, x] })#L] 

Error:(9, 9) could not find implicit value for evidence parameter of type scalaz.Applicative[[x]scalaz.EitherT[scala.concurrent.Future,String,x]]

另一个从Scalaz Monad Transformers

type Result[A] = OptionT[Future, A] 
"".point[Result] 

Error:(8, 10) could not find implicit value for evidence parameter of type 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._ 

回答

6

导入ExecutionContext会让你的解决方案的编制,见scalaz.std.scalaFuture

import scala.concurrent.ExecutionContext.Implicits.global 

type Result[A] = OptionT[Future, A] 
"".point[Result] 
// Result[String] = OptionT([email protected]) 

1.point[Future].liftM[OptionT] 
// scalaz.OptionT[scala.concurrent.Future,Int] = OptionT([email protected]) 
+0

点上!原来'futureMonoid'需要一个隐含的执行上下文......我希望这些教程已经提到过这个细节* *。 – dcastro