I have written this code
import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
import cats.Applicative
import cats.data.OptionT
import cats.instances.future._
import cats.syntax.applicative._
object PureTest extends App {
type FutureOption[T] = OptionT[Future, T]
val x1 = Applicative[FutureOption].pure(1)
val y1 = 1.pure[FutureOption]
println(x1)
println(y1)
val x2 = Foo(1).pure[FutureOption]
val y2 = Bar("1").pure[FutureOption]
println(x2)
println(y2)
val z1 = (Foo(1), Bar("1")).pure[FutureOption]
println(z1)
}
case class Foo(i: Int)
case class Bar(s: String)
This is my build.sbt
name := "PureTest"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"org.typelevel" % "cats-core_2.11" % "0.9.0"
)
This code compiles and works fine.
If I add a line import cats.implicits._
as one of the imports, then I get compilations errors
Error:(16, 14) value pure is not a member of Int
val x = 1.pure[FutureOption]
Error:(17, 16) value pure is not a member of String
val y = "1".pure[FutureOption]
Error:(18, 21) value pure is not a member of (Int, String)
val z = (1, "1").pure[FutureOption]
Error:(19, 32) value pure is not a member of (PureTest.Foo, PureTest.Bar)
val z1 = (Foo(1), Bar("x")).pure[FutureOption]
Why does importing the implicits._
break the code?