, 12 tweets, 2 min read Read on Twitter
The current Cats Effect hierarchy definitely has some significant issues. Bracket is overly-restrictive and at the top of the hierarchy. Sync and Async are all-powerful and pollute every typeclass use-site. But the abstractions are still profoundly useful. 1/n
When the hierarchy was originally built, Sync/Async and Effect were pretty much all that existed. It was an abstraction for constructing and (optionally) running effects. The addition of Concurrent made it much more about control flow. 2/n
Having Concurrent under Async was a sensible choice at the time, since all Concurrent types will also be Async, but it also means that you're forced to inherit the almighty Sync/Async pair just to get at Concurrent/Fiber, and Sync/Async can do *anything*. 3/n
The solution here is relatively obvious: move Concurrent above Sync/Async and ensure that you can avoid that pair in most usage, which is something we'll do in CE 3. There are other issues though. 4/n
Another major problem is Bracket. Bracket describes a *static* resource scope suspended in F[_], where the acquisition is also described by F[_]. This is a very very restrictive type that can't be implemented by many otherwise-lawful effect datatypes (such as streams). 5/n
Bracket is *also* high up in the hierarchy. In fact, Sync <: Bracket, which transitively restricts everything to be… very very much like IO. It kicks out Monix's Iterant and fs2's Stream, not to mention all other such types. 6/n
The solution here, again, is to fix the hierarchy. And there are several ways to address this, and they will be addressed in Cats Effect 3.0. But all of this loops full-circle to the question: why bother at all? Why abstract? 7/n
The answer is relatively simple: you want to push your concretization to the leaves of your stack. This is *always* the right approach with abstractions, regardless of what you're abstracting over. It gives you much more power and flexibility. 8/n
As an example of where this can be helpful even with the current (highly restricted) hierarchy, monad transformer stacks allow arbitrary composition of certain classes of effects. Most CE typeclasses derive inductively over MTL stacks and the result is very poweful. 9/n
Now, MTL carries some significant performance penalties, but those performance penalties are never in the hot path if you're doing things correctly, and are thus generally negligible when you measure application-level characteristics. 10/n
The point being that, even in its current flawed state, the CE typeclass hierarchy provides real abstractive power and enables things that would be otherwise impossible. This will be substantially improved and extended in CE 3. 11/n
The best way to derive value from Cats Effect and its abstractions is to use them essentially the way that the library ecosystem does. Look at Monix, fs2, http4s, doobie, and so many others. The way they use the library is as time-tested as anything. Follow those patterns. 12/12
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Daniel Spiewak
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!