0

I have the following code:

import cats._
import cats.Functor

object StudyIt {

  def main(args: Array[String]): Unit = {
    val one: Int = 1
    val a = Functor[Id].map(one)(_ + 1)
    println(a)
  }

}

As you can see, map expects the type of Id[Int] but I just past Int to map, why it is possible?

softshipper
  • 32,463
  • 51
  • 192
  • 400

2 Answers2

5

That's because Id is just a type alias, which gets completely inlined at runtime. It looks like this:

type Id[A] = A

So in essence Id[Int] and Int are the exact same type.

Luka Jacobowitz
  • 22,795
  • 5
  • 39
  • 57
2

That's because Id[A] is literally defined as just A

type Id[A] = A

so that Id[Int] is just an alias for Int.

Here is it, as one of the first definitions (line 34): Github link.

Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93