Manually import Cats external dependency in scala compiler

Hi all,

I’m trying to manually import an external package: cats-effect-2 in my scalac script.
Actually I tried this script:

scalac -feature -deprecation -unchecked -language:postfixOps -language:higherKinds -Ypartial-unification -Yresolve-term-conflict:package src/main/scala/Applicazione-analisi-accessi-fraudolenti-CATS-EFFECT.scala

This should insert all the specified options (deprecation, unchecked …) like mentioned in the official cats-effect documentation: https://typelevel.org/cats-effect/docs/getting-started

But I’m not able to edit my scalac script to include all the cats-effect packages.
Actually my only external dependecy is the cats itself:

libraryDependencies += "org.typelevel" %% "cats-effect" % "2.5.3" 

Using “sbt compile” it runs flawlessly, with my build.sbt:

name := "ApplicazioneAnalisiAccessiFraudolenti"
version := "1.0"
scalaVersion := "2.12.10"

scalacOptions ++= Seq(
  "-feature",
  "-deprecation",
  "-unchecked",
  "-language:postfixOps",
  "-language:higherKinds",
  "-Ypartial-unification",
  "-Yresolve-term-conflict:package")

libraryDependencies += "org.apache.spark" %% "spark-core" % "3.1.2"
libraryDependencies += "org.apache.hadoop" % "hadoop-client" % "2.10.1"
libraryDependencies += "org.typelevel" %% "cats-effect" % "2.5.3" withSources() withJavadoc()

Can you please help me to update my scalac to integrate all the cats-effect-2 dependencies?

Thank you

Why do you want to run scalac directly at all?

BTW, a bit off topic, but why CE2? CE3 is way better in all aspects.

1 Like

I want to practice with cats library. Sbt compilation is slow, and also I need an active prompt with all the cats dependencies loaded in cache. I use a cloud instance of GCP, and want to configure this instance to get an active prompt.
Does exist a better configuration than a scalac script? Maybe a Docker image? Some advice?
Thank you

I want to practice with cats library

What part of cats do you want to practice?
If you only want to get familiar with the syntax and other utilities, just include the core library.
If you want to get familiar with the “programs as values” paradigm, then use CE3, it makes it easier and simpler.
If you want to get familiar with the FP jargon from CT and typeclasses then check the Red Book (and also, you only need the core module); but, IMHO, don’t waste your time with that.

Sbt compilation is slow

It won’t be anymore slower than plain scala unless you shutdown the sbt server between commands… if you are doing that, then don’t.

also I need an active prompt with all the cats dependencies loaded in cache

Just launch the console task on your sbt REPL.
It seems you are not familiar with sbt at all, check this: sbt Reference Manual — sbt by example
Also, if you are not even familiar with sbt I wonder if cats and even worse cats-effect may be too much to bite at once.

I use a cloud instance of GCP, and want to configure this instance to get an active prompt.

Uhm, no idea how that matters at all?
Like are you SSH into that or what?

Does exist a better configuration than a scalac script? Maybe a Docker image? Some advice?

It depends, what are you trying to do? What is your back ground? What do you already know? What is your end goal?

First I would lire to get familiar with “semigroup” type, and IO-Monad, then Fibers and multi tasking programming.

It would the same to include even only the cats-core., but dan it be include in scala compiler or do I need sbt?

Why should I not waste my time with typeclassess?

My final goal would be to have a configured development environment, but I can’t use an IDE cause i’m using a command-line only instance.

"Launch the console task on your sbt " would be just an interface to sbt, not to scala. I could interact only with sbt tool. Correct?

I know cats is huge. It doesn’t matter. I’m studying, and I like it.

A Semigroup is just a typeclass (more info in what that words means here: Polymorphism in Scala. · GitHub) that provides a combine operation with the following signature:

```scala`
trait Semigroup[A] {
def combine(a1: A, a2: A): A
}


The important bit is that such a combine operation has to be associative, e.g. 

```scala
combine(a1, combine(a2, a3)) === combine(combine(a1, a2), a3)

That is all.
The nice thing of it, is that it allows us to write higher level combinators, like combineAll and foldMap


The important bit of IO is to understand that it provides a different programing paradigm, called “programs as values”. I have some examples and resources about it here: GitHub - pslcorp/programs-as-values: Source code of the programs as values presentation

If your end goal is to learn this paradigm, I would recommend joining the typelevel discord: Discord since you may have a lot of questions.


You can manage all the dependencies manually… but really, nobody does that, and is a total pain.
If you don’t want to use sbt (for whatever reason) check scala-cli: https://scala-cli.virtuslab.org/


Because you don’t need to care about those most of the time.
People get the impression that we FP developers create new Monads every day, but we don’t.
Rather, either learn how to use cats as a toolbox and / or learn the IO datatype and the “programs as values” paradigm.

Yeah, no idea how you would that on a GCP instance, I believe github does have some developer instances. Or you may check vscode and its remote extension.

No, the console task inside the sbt REPL loads a scala REPL with all your code and libraries loaded. Check the link I shared in my previous message.