exercises-cats
exercises-cats copied to clipboard
Monad last exercise doesn't compile
The following code doesn't compile:
implicit def optionTMonad[F[_]](implicit F: Monad[F]) = {
new Monad[OptionT[F, ?]] {
def pure[A](a: A): OptionT[F, A] = OptionT(F.pure(Some(a)))
def flatMap[A, B](fa: OptionT[F, A])(f: A => OptionT[F, B]): OptionT[F, B] =
OptionT {
F.flatMap(fa.value) {
case None => F.pure(None)
case Some(a) => f(a).value
}
}
}
}
Running this code gives this error messages:
<console>:37: error: not found: type ?
new Monad[OptionT[F, ?]] {
^
<console>:37: error: OptionT[F,<error>] takes no type parameters, expected: one
new Monad[OptionT[F, ?]] {
I'm running this in the REPL launched with sbt console and this build.sbt file:
name := "Scala Playground"
version := "1.0"
scalaVersion := "2.11.1"
libraryDependencies += "org.typelevel" %% "cats" % "0.6.1"
PS: Also, it's not very clear what's the point of this last exercise nor the result it should give... Maybe some extra explanation would make it easier to understand, especially about the type parameters' meanings in OptionT and optionTMonad...
Tried with this build.sbt:
name := "Scala Playground"
version := "1.0"
scalaVersion := "2.11.1"
resolvers += Resolver.sonatypeRepo("releases")
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.8.0")
libraryDependencies += "org.typelevel" %% "cats" % "0.6.1"
Failing to compile as well.