How to use cats IO with scalac

Trying IO, which resides in cats library I receive error cats not found using:
scalac test.scala on a program with
import cats…
My scala version is 3.1.0

Uhm, you would need to download the cats-effect JAR and all its dependencies JARs and put them in the compiler classpath…
But really, nobody ever does this, we have build tools for a reason, like sbt.

Create a new folder for your code; I will refer to that folder as app but it can be named in any way-
In that folder create a build.sbt file like this:

name := "app" // Again, this can be any name; is common to match the folder name.
scalaVersion := "3.1.2"

libraryDependencies ++= Seq(
  "org.typelevel" %% "cats-core" % "2.7.0", // While this is pulled transitivelty by cats-effect, it is recommended to be explicit about it.
  "org.typelevel" %% "cats-effect" % "3.3.12"
)

Then crate a folder project inside app and then a file project/build.properties with this line

sbt.version=1.6.2

And finally, create the Main of your code in this file app/src/main/scala/example/Main.scala

package example

import cats.effect.{IO, IOApp}

object Main extends IOApp.Simple {
  override final val run: IO[Unit] =
    IO.println("Hello, world!")
}
1 Like