Looking at part of the IO Monad
's signatures from Functional Programming in Scala:
trait IO[+A] { self =>
def run: A
def map[B](f: A => B): IO[B] =
new IO[B] { def run = f(self.run) }
As I understand, IO[+A]
means that the IO
type takes a type parameter of "A or its subclasses."
Looking at def map[B]...
, B
is a type involved in this function. It's useful to use map[B](f: A => B): IO[B]
since, as I understand, you can list B
as a return type of f
, as well as the returned type parameter of IO
?
So, the following implementation would cause a compile-time problem:
map(f: Int => String): IO[Int]