Purely functional Scala code needs something like Haskell's IO monad—a construct that allows functional programs to interact with external, effectful systems in a referentially transparent way. To date, most effect systems for Scala have fallen into one of two categories: pure, but slow or inexpressive; or fast and expressive, but impure and unprincipled. In this talk, John A. De Goes, the architect of Scalaz 8’s new effect system, introduces a novel solution that’s up to 100x faster than Future and Cats Effect, in a principled, modular design that ships with all the powerful primitives necessary for building complex, real-world, high-performance, concurrent functional programs.
Thanks to built-in concurrency, high performance, lawful semantics, and rich expressivity, Scalaz 8's effect system may just be the effect system to attract the mainstream Scala developers who aren't familiar with functional programming.
16. Scalaz8Effectimport scalaz.effect._
Scalaz 8 effect system is a small, composable collection of data
types and type classes that help developers build principled,
performant, and pragmatic I/O applications that don't leak
resources, don't block, and scale across cores.
17. Scalaz8IO
TheHeartofScalaz8
IO[A] is an immutable value that describes an effectful program
that either produces an A, fails with a Throwable, or runs forever.
18. TLDR
Scalaz 8 IO helps you quickly build
asynchronous, concurrent, leak-free, performant
applications.2
2
Which coincidentally happen to be type-safe, purely functional, composable, and easy to reason about.
20. Main
SafeApp
object MyApp extends SafeApp {
def run(args: List[String]): IO[Unit] =
for {
_ <- putStrLn("Hello! What is your name?")
n <- getStrLn
_ <- putStrLn("Hello, " + n + ", good to meet you!")
} yield ()
}
31. Asynchronous
EffectImport:Definition
object IO {
...
def async0[A](k: (Throwable / A => Unit) => AsyncReturn[A]): IO[A] = ???
...
}
...
sealed trait AsyncReturn[+A]
object AsyncReturn {
final case object Later extends AsyncReturn[Nothing]
final case class Now[A](value: A) extends AsyncReturn[A]
final case class MaybeLater[A](canceler: Throwable => Unit) extends AsyncReturn[A]
}