Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Doobie use free monad?

Tags:

scala

doobie

It seems that simple

type Db[F[_], A] = Kleisli[F, Connection, A]
type Transactor[DB[_], F[_]] = DB ~> F

Сan be used to build functional JDBC layer as well

like image 396
Sergey Alaev Avatar asked Jun 10 '19 10:06

Sergey Alaev


1 Answers

Summed up from @SystemFw and @tpolecat answers from https://gitter.im/scala/scala?at=5cfe6505bf4cbd167c619960

Pros of Free Monad:

  • client code has no access to Connection instance and therefore can't leak it
  • there is no user's F[_] so improper (asynchronous) effect can't be used within transaction boundary. It is important since most JDBC drivers have designed java.sql.Connection implementation to be single-threaded.

Cons of Free Monad:

  • client code has no access to Connection and therefore can't use alternative ORMs (like JOOQ)
  • there is no user's F[_] so you can't nest specific effects within transaction.

Doobie will have tagless version in the future.

like image 123
Sergey Alaev Avatar answered Oct 10 '22 01:10

Sergey Alaev