docs| typelevel.org
In recent years, Typelevel has existed in a somewhat grey area legally. We have long managed a good deal of intellectual property (the Organization Libraries) and raised funds. In 2022, we adopted a Charter establishing our governance. However, we have not had a well-defined legal status. We have decided it is time to become a legally-recognized organization. To that end, we have formed the Typelevel Foundation, a nonprofit organization incorporated in the United States, in the state of Calif...| Typelevel
Typelevel is an ecosystem of projects and a community of people united to foster an inclusive, welcoming, and safe environment around functional programming in Scala.| typelevel.org
We are delighted to announce the release of weaver-test under Typelevel. What is weaver? Weaver is a test framework for integration and end-to-end testing. It makes tests faster and easier to debug by using cats, cats-effect and fs2. Weaver provides a high quality experience when writing and running tests: Tests within a suite are run in parallel for the quickest results possible. This is especially suited to IO heavy tests, such as those making API calls or reading files. Expectations (ie as...| Typelevel
This project was proposed by the Typelevel community in collaboration with the Scala Center, and carried out under Google Summer of Code (GSoC) 2024. Feral is a library in the Typelevel ecosystem that provides a framework for Scala developers to write and deploy serverless functions. As Feral was only supporting AWS Lambda, the goal of the project was to extend Feral to support other serverless providers, specifically Vercel and Google Cloud. The vision for Feral is to enable Scala developers...| Typelevel
We are proud to announce that Typelevel is a Mentoring Organization for Google Summer of Code 2025! If you are a student, this is a wonderful opportunity to spend your summer working on Scala open source projects with mentorship from Typelevel maintainers, while earning a stipend. You can learn more about what the experience is like in this blog post by our 2024 contributor Ching Hian Chew. Please check out our project ideas and mentors spanning AI/ML, serverless, build tooling, frontend/UIs,...| Typelevel
We’re excited to announce that Typelevel has been chosen as a recipient of the 2024 Spotify FOSS Fund! As a result, Spotify has donated €20,000 to Typelevel’s OpenCollective. Our current funding goes towards recurring infrastructure expenses, and sending members of our code of conduct committee for training to better support our community. With these extra funds we’d like to expand our initiatives to encourage and support new contributors and users! We’ve specifically discussed fund...| Typelevel
docs| typelevel.org
A few months back the Typelevel Steering Committee put out a call for new members to join the Typelevel Code of Conduct Committee. Thank you very much to all who applied, it’s lovely to see folks interested in keeping our community safe. Since that time, the Typelevel Steering Committee voted in three new members to the Code of Conduct Committee! The committee now has five members total. Here are some brief introductions to our current committee members. Lucas Satabin (he/him) I’ve been u...| Typelevel
Are you passionate about fostering a positive and inclusive community? Do you want to help shape how Typelevel works with the community to build a respectful environment for all? We’re excited to announce this call for new members to the Typelevel Code of Conduct Committee! Earlier this year Typelevel adopted a new Code of Conduct that encompasses both organization and affiliate projects. The Typelevel Code of Conduct Committee’s mission is to enforce that Code of Conduct to help maintain...| Typelevel
We have recently adopted a new Code of Conduct and Enforcement Policy. This change was approved by the Steering committee after a 1 month discussion and voting period. Thank you to everyone who engaged! The scope of the Typelevel Code of Conduct and Enforcement Policy encompasses both organization and affiliate projects (as described in the Typelevel Charter). While the Typelevel Charter has always specified that affiliate projects must adhere to the Typelevel organization policies, including...| Typelevel
As we continue to grow our community on GitHub, we’ve encountered a challenge with our seat limit for maintainers. It’s important to note that each maintainer seat incurs a fee. By managing our maintainers more efficiently, we can allocate resources effectively and sustain the growth of our community. In order to be able to add new members, we’ve recently conducted a review and removed 25 accounts that have not been active on the organization since January 1st, 2023. We understand that ...| Typelevel
We are excited to share that Typelevel will be participating in Google Summer of Code 2024, thanks to the gracious support of the Scala Center! If you are a student, this is a wonderful opportunity to spend your summer working on Scala open source projects with mentorship from Typelevel maintainers, while earning a stipend. This year we have several project ideas and mentors lined up spanning AI/ML, serverless, data streaming, observability, systems programming, and more. We will continue add...| Typelevel
This week the Steering Committee updated the Typelevel Charter. The updates are minimal and intended to clarify the role of Chair. First, the role has been renamed to Secretary. We believe that this renaming is more aligned with the function of the role, as it is not intended to be a leadership position, but is instead responsible for the administrative running of the committee (notably, calling votes). We have also opted to convert the role to a rotating position, with a term of 12 months so...| Typelevel
Getting started in the wondrous world of functional programming using Typelevel libraries can be daunting. Before you can even write your first pure “Hello, World!” you’ll need to install a Java runtime, editor tooling and build tools. Then you’ll need to setup some project using sbt or mill. As an added consequence, after all the setup, the idea of using these battle-tested libraries for small scripts will seem like a chore. This is where Typelevel Toolkit comes in. It provides an ea...| Typelevel
We are happy to announce that Typelevel will be participating in Google Summer of Code 2023, under the auspice of the Scala Center! If you are a student, this is a wonderful opportunity to spend your summer working on Scala open source projects with mentorship from Typelevel maintainers, while earning a stipend. We are proposing the following three projects: io_uring backend for Cats Effect + FS2 JVM for efficient, non-blocking network I/O. This will be the flagship of the Cats Effect I/O Int...| Typelevel
I know what you’re thinking! “A new JSON library? Why? Don’t we have plenty of those?” Well, the short answer is a resounding yes, but the idea of this library is simplicity and convenience. This library benefited a great deal from the things I liked about the existing libraries, but hopefully offers some convenience features and simplifications that are entirely new. Once I wrote the library I wanted to do some sanity-checking to make sure the performance wasn’t substantially worse...| Typelevel
We recently published several major Typelevel projects for the Scala Native platform, most notably Cats Effect, FS2, and http4s. This blog post explores what this new platform means for the Typelevel ecosystem as well as how it works under-the-hood. What is Scala Native? Scala Native is an optimizing ahead-of-time compiler for the Scala language. Put simply: it enables you to compile Scala code directly to native executables. It is an ambitious project following in the steps of Scala.js. Inst...| Typelevel
We are pleased to announce that we have set up a Typelevel team for Tuple, a remote pair-programming application. Tuple provides screen-sharing, audio and video calls (video is optional), as well as a very helpful screen drawing feature for whiteboarding. Tuple clients are available for MacOS and Linux (beta). We hope that Tuple will help the community by enabling maintainers to collaborate together more easily, and as a new way to onboard and share knowledge with new contributors. There are ...| Typelevel
In August, you may have noticed that Typelevel.org has a new layout! We are grateful to our old friends at 47 Degrees for their generously donated time and effort in planning, designing, and implementing this long-needed revamp. Our deepest thanks to the following individuals from 47 Degrees for working with our Steering Committee on a proposal: Israel “Isra” Pérez, Jetro Cabau Quirós, Maureen Elsberry, Benjy Montoya, and Raúl Raja Martínez. Special thanks again to Isra for the months...| Typelevel
Since our last post, the Typelevel Steering Committee has happily welcomed six new members to our group: Zach McCoy, Sam Pillsworth, Jasna Rodulfa-Blemberg, Andrew Valencik, Vasil Vasilev, and Mark Waks (aka Justin du Coeur). In their own words: Zach McCoy (he/him) I’ve been programming in Scala professionally for 10 years. I currently work at Jack Henry where I get to work in Scala and deal with observability in systems. I’m based in Iowa where I work remotely. I can usually be found rea...| Typelevel
The Typelevel Steering Committee is opening a call for new members as we continue to build a more transparent and sustainable community. In 2021, co-founders Lars Hupel and Miles Sabin stepped down from leadership. We are all grateful for what they created and their several years of service. What remains is a generation of leadership that has not expanded in a few years. Retirements and additions alike are healthy, balancing institutional memory with fresh energy. It is again a time for renew...| Typelevel
As a first step in our effort to increase transparency in the Typelevel organization, the Steering Commitee have approved and released an initial set of Governing Documents. The most important document is the Charter, which specifies the role of the Steering Committee and criteria for member projects. The most notable change is that Typelevel no longer distinguishes “full” and “incubator” projects, but instead recognizes: Affiliate Projects. These projects agree to use an approved lic...| Typelevel
Open source developers are free to choose the projects they contribute to and the communities they support. Martin Odersky’s recent objection to an exercise of this freedom threw the community into turmoil. We believe that those who questioned his intervention and spoke out were justified in doing so. Regardless, we encourage everyone to consider the tone and weight of their words before hitting “send”. We stand with those who feel excluded by the notion of politics being somehow option...| Typelevel
Hello Community! We have a new Typelevel discord server. There is a large and growing community of Scala developers on Discord. Gitter has struggled as a platform for Typelevel for many reasons. We have received feedback that the platform is hard to approach, and that the sense of community is fractured by being in separate rooms, and difficult for beginners since you have to know where to get started. Additionally, mobile support has completely deteriorated throughout the years. The only use...| Typelevel
Effective today, Jon Pretty is barred from participating in Typelevel projects and events. We make this decision based on well-substantiated reports of predatory behavior at Scala conferences, including conferences at which Typelevel Summits were co-located. All conference organizers aspire to create safe spaces for attendees, and succeed to varying degrees. Our efforts have been insufficient. We pledge to review our process and practices for event safety, and will provide details on concrete...| Typelevel
With Cats Effect 3.0 right around the corner, we’ve been publishing a lot of numbers and scenarios which demonstrate disorientingly high performance in a lot of realistic setups. At first glance, this seems to defy intuition. After all, IO is quite a heavyweight abstraction; how is it that it can be competitive with hand-written and hand-tuned code for the same use-case? There are a lot of ways to answer this question, and they get both complex and depend heavily on exactly what use-case yo...| Typelevel
Cats Effect 3 is just around the corner! The library has seen several major changes between 2.0 and 3.0, so in an effort to highlight those changes, we will be releasing a series of blog posts covering a range of topics. If you would like to see a blog post about a particular subject, don’t hesitate to reach out! You can try out early Cats Effect 3 releases here. Introduction In this post, we offer a broad overview of the concurrency model that serves as the foundation for Cats Effect and i...| Typelevel
In the wake of unrest in the United States and elsewhere following the deaths of George Floyd, Ahmaud Arbery, Breonna Taylor, and countless others, it is important for us to consider the impact of racism in every sector of our lives. This includes taking a long, hard look at race and racism in our community In this blog post, I want to discuss the problem briefly and then begin to look at ways that individuals and organizations can learn about racism and to make changes to improve diversity, ...| Typelevel
Six months ago, we launched the Typelevel sustainability program to provide more ways for our community to help support Typelevel projects. Since then, we received numerous donations from individuals as well as corporations, now bringing our estimated annual budget to over $18,000. We are incredibly grateful for the generosity of our community. From the bottom of our hearts, thank you! Our original plan was to use the donation to hire a part-time dedicated maintainer to help support participa...| Typelevel
Effective today, John De Goes has been indefinitely barred from participation in Typelevel projects. This most directly impacts Cats Effect, but applies to our other repositories as well. The cause is John’s combative style of interaction in Typelevel channels. His interactions when in agreement are always cordial, but when he disagrees with something or someone, the results are inevitably drawn out, intensely aggressive, and stressful. We have tried for the past three years, via one-on-one...| Typelevel
Hello Community! As you all know, back in April we announced the Typelevel Sustainability Program and we have been delighted by the overwhelming support we received both from companies and individuals: thank you all! In just a little bit more than one month we reached 10% of the fundraising goal we set to $150,000. While this is an excellent start, to successfully support the long term sustainability of our ecosystem, we need you to keep advocating for us. One difficulty we are aware of is th...| Typelevel
Typelevel is pleased to announce that we are retiring the Typelevel Code of Conduct in favour of the Scala Code of Conduct. Many of the major projects under the Typelevel umbrella have already made the switch and we will be asking new projects that join Typelevel to adopt the new code. The Scala Code of Conduct was developed by the Scala Center with input from Typelevel and Lightbend, and improves on Typelevel’s original in several ways. It can be thought of as the “Typelevel code of cond...| Typelevel
We are excited to announce the Typelevel sustainability program. The ultimate goal for this program is to provide ways for the user community to ensure the long-term sustainability of the development and maintenance of some Typelevel libraries. Currently, these libraries are maintained in their contributors’ spare time. This arrangement has worked so far but we want to firmly secure their long term sustainability with an institution dedicated to supporting the maintenance of these mission c...| Typelevel
In this post we are going to explore the concept of algebraic API design which is based on types, pure functions, and the relationships between them known as domain rules or properties. We will do this based on a complete, self-contained example using Cats and Cats Effect and walk through the process of designing and implementing the domain of solving complex, deterministic single player games. An API in this context describes the types and operations that a module exposes to the user. SameGa...| Typelevel
Overall we received 588 responses over the course of 30 days. This feedback is essential for us to make informed decisions on our 2019 plan. Thank you, everyone, who participated. As promised, here are the results, as well as some quick reads from us. Q: How long have you been using the Cats ecosystem (including Cats and Cats ecosystem libraries)? Results: Our read: 46% of the respondents are relatively new (less than 1 year) users. Welcome! Q: Do you feel welcome in the Cats ecosystem commun...| Typelevel
This is a continuation of my previous blog post. Make sure you have read that one before continuing here. I recently gave a 20 minutes talk on classy optics at the unconference of Scale by the Bay where I also talked about this error handling technique and on my way back home I was still thinking of different ways of doing this. So, after some exploratory work, I came up with a few different alternatives. Issues with first approach Something that made me cringe and that a few of my colleagues...| Typelevel
Ever wondered why sum types are called sum types? Or maybe you’ve always wondered why the <*> operator uses exactly these symbols? And what do these things have to do with Semirings? Read this article and find out! Most of us know and use Monoids and Semigroups. They’re super useful and come with properties that we can directly utilize to gain a higher level of abstractions at very little cost (In case you don’t know about them, check out the Cats documentation for some insight). Someti...| Typelevel
MTL is a library for composing monad transformers and making it easier to work with nested monad transformer stacks. It originates from the land of Haskell, but has made it into Scala a long time ago. For the longest time however, it was barely usable, because of a bunch of different Scala quirks coming together. With all this, I feel many have the impression that mtl is something scary, abstract or too complicated. In this blog post, I’ll try my best to disprove this notion and demonstrate...| Typelevel
A question that repeatedlypopsup about Cats is why monad transformer types like OptionT and EitherT aren’t covariant like their Option and Either counterparts. This blog post aims to answer that question. Covariance What does it mean to say that Option is covariant? It means that an Option[B] is allowed to be treated as an Option[A] if B is a subtype of A. For example: abstract class Err(val msg: String) final case class NotFound(id: Long) extends Err(s"Not found: $id") val optionNotFound: ...| Typelevel
List is a great data type, it is very simple and easy to understand. It has very low overhead for the most important functions such as fold and map and also supports prepending a single element in constant time. Traversing a data structure with something like Writer[List[Log], A] or ValidatedNel[Error, A] is powerful and allows us to precisely specify what kind of iteration we want to do while remaining succint. However, in terms of efficiency it’s a whole different story unfortunately. Tha...| Typelevel
As a longtime http4s user I keep on learning new things and I’m always trying to come up with the best practices for writing http applications. This time I want to talk about my latest achievements in error handling within the context of an http application where it basically means mapping each business error to the appropiate http response. So let’s get started by putting up an example of an http application with three different endpoints that interacts with a UserAlgebra that may or may...| Typelevel
I was recently cleaning up some Scala code I’d written a few months ago when I realized I had been structuring code in a very confusing way for a very long time. At work, we’ve been trying to untangle the knots of code that get written by different authors at different times, as requirements inevitably evolve. We all know that code should be made up of short, easily digestible functions but we don’t always get guidance on how to achieve that. In the presence of error handling and nested...| Typelevel
Writing tests seems like a wonderful idea in theory but real systems can be a real pain to test. Today I want to show a few tips on how to use specs2 + ScalaCheck to make some real-world testing somewhat bearable. I am currently refactoring a big piece of code. Such refactoring is more like a small rewrite and some of our previous tests also have to be rewritten from scratch. I will try to introduce you to the problem first. Creating articles The system-du-jour is called “Panda” (we have ...| Typelevel
In our previous post on optimizing tagless final programs we learned how we could use the sphynx library to derive some optimization schemes for your tagless final code. In case you missed it and want to read up on it, you can find it right here or you can watch my presentation on the topic here, but you should be able to follow this blog post without going through it all in detail. Optimizing monadic programs One of the questions I’ve been getting a lot, is if we can also do something like...| Typelevel
In this blog post, I will show you how to leverage Scala’s type system to derive an HTTP client function from a single type. This will also be the story of how I started to work on Typedapi which is basically the attempt to bring Haskell’s Servant to Scala. Servant in a nutshell and how it began For everyone not knowing Servant, it is a library which lets you define your web apis as types and derives the client and server functions from it. When I saw it for the first time while working o...| Typelevel
Newcomers to functional programming (FP) are often very confused about the proper way to share state without breaking purity and end up having a mix of pure and impure code that defeats the purpose of having pure FP code in the first place. This is the reason that has motivated me to write a beginner friendly guide :) Use Case We have a program that runs three computations at the same time and updates the internal state to keep track of the tasks that have been completed. When all the tasks a...| Typelevel
There have been a couple of really nice blog posts about Tagless Final and some related topics. However, I have faced some design problems when writing some algebras and haven’t seen anybody talking about. So please let me introduce this problem to you. Algebra definition Given the following data definition: case class ItemName(value: String) extends AnyVal case class Item(name: ItemName, price: BigDecimal) Consider the following algebra: trait ItemRepository[F[_]] { def findAll: F[List[Ite...| Typelevel
A somewhat common Scala idiom is to make an abstract type extend Product with Serializable. There isn’t an obvious reason to do this, and people have asked me a number of times why I’ve done this. While I don’t think that Product or Serializable are particularly good abstractions, there’s a reason that I extend them. Let’s say that I’m writing a simple enum-like Status type: object EnumExample1 { sealed abstract class Status case object Pending extends Status case object InProgres...| Typelevel
MonadError is a very old type class, hackage shows me it was originally added in 2001, long before I had ever begun doing functional programming, just check the hackage page. In this blog post I’d like to rethink the way we use MonadError today. It’s usually used to signal that a type might be capable of error handling and is basically like a type class encoding of Eithers ability to short circuit. That makes it pretty useful for building computations from sequences of values that may fai...| Typelevel
The Tagless Final encoding has gained some steam recently, with some people hailing 2017 as the year of Tagless Final. Being conceptually similar to the Free Monad, different comparisons have been brought up and the one trade-off that always comes up is the lack or the difficulty of inspection of tagless final programs and in fact, I couldn’t find a single example on the web. This seems to make sense, as programs in the tagless final encoding aren’t values, like programs expressed in term...| Typelevel
The cats maintainer team is proud to announce the cats 1.0.0 release. Cats has been striving to provide functional programming abstractions that are core, modular, approachable and efficient. Cats 1.0.0 marks the point where we believe that our API is robust and stable enough to start guarantee backward binary compatibility going forward until Cats 2.0. We expect the Cats 1.x series to be fully backwards compatible for at least one year. This is a major milestone towards our goal of providing...| Typelevel
The typeclass pattern in Scala invites you to place implementation-specific knowledge directly in the typeclass instances, with the interface defined as the typeclass’s abstract interface. However, GADTs permit a different organization of code. It is even possible to define a typeclass that seems to do nothing at all, yet still permits full type-safe typeclass usage. The possibilities between these two extremes form a design space. If you wish to practice ad-hoc polymorphism in Scala, this ...| Typelevel
Newtype mechanisms are a great way to introduce wrapper-free, global distinctions of “different” instances of the same type. But we can do that on a local level, too, by using type parameters. Consider these two signatures. def mungeIDs(uids: List[String], gids: List[String], oids: List[String]): Magic[String, String, String] def mungeIDsSafely[UID <: String, GID <: String, OID <: String] (uids: List[UID], gids: List[GID], oids: List[OID]): Magic[UID, GID, OID] The second function is a st...| Typelevel
The cats maintainer team is proud to announce the cats 1.0.0-MF release. MF stands for milestone final, this will be the last release before cats 1.0.0-RC1 which will be followed by cats 1.0 shortly. The main purpose/focus of this release is to offer a relatively stable API to work with prior to the official 1.0. It can be deemed as a proposal for the final cats 1.0 API. Please help test it and report any improvements/fixes needed either in the cats-dev gitter channel or as github issues. Pos...| Typelevel
The need for configuration arises in almost every application, as we want to be able to run in different environments – for example, local, testing, and production environments. Configurations are also used as a way to keep secrets, like passwords and keys, out of source code and version control. By having configurations as untyped structured data in files, we can change and override settings without having to recompile our software. In this blog post, we’ll take a look at configurations ...| Typelevel
Dimensional analysis When we code, we code in numbers - doubles, floats and ints. Those numbers always represent real world quantities. For example, the number of people in a room can be represented as an integer, as can the number of chairs. Adding people and chairs together gives a nonsensical result, but dividing the number of people by the number of chairs gives a useful indicator of how full up the room is. val numberOfPeople = 9 val numberOfChairs = 10 numberOfPeople + numberOfChairs //...| Typelevel
Haskell is a pure language. Every Haskell expression is referentially transparent, meaning that you can substitute that expression with its evaluated result without changing the program. Or, put into code: -- this program f expr expr -- apply function f to arguments expr, expr -- is equivalent to this one, which factors out `expr` let x = expr -- introduce a new variable `x` with the value of `expr` in f x x And this is true for all expressions e, and all functions f. These could be complex e...| Typelevel
This is a guest post by Tomas Mikula. It was initially published as a document in the hasheq. It has been slightly edited and is being republished here with the permission of the original author. This article describes what we mean when we say that the data structures in this library are equivalence-aware in a type-safe fashion. Equivalence Set is a data structure that doesn’t contain duplicate elements. An implementation of Set must therefore have a way to compare elements for “sameness...| Typelevel
The mixin style of importing in which classes and traits are defined within traits, as seen in scala.reflect.Universe, ScalaTest, and other Scala styles, seems to be infectious. By that, I mean once you define something in a trait to be mixed in, to produce another reusable module that calls that thing, you must define another trait, and so must anyone using your module, and so on and so forth. You effectively become “trapped in the cake”. However, we can use type parameters that represen...| Typelevel
As programmers, we are very incautious with our use of the word “type”. The concept of “type” is sufficiently abstract and specific that we are tempted to understand it by analogy, so much that we begin to confuse analogy with sameness. The colloquial “runtime type”, a fair approximation of “class”, makes it tempting to equate types with “classes, interfaces, traits, that sort of thing”, which I will name classes for the rest of this article. But they aren’t the same. Th...| Typelevel
A couple of days ago, the new Scala Code of Conduct was published. It applies to all official Scala channels, including mailing lists, Gitter channels and GitHub repositories. We would like to take this opportunity to endorse this new Code of Conduct. From our perspective, it does a good job of listing encouraged behaviour, instead of just banning harassment: It reflects the goal of actively creating a welcoming community. Also, we consider it to be a decent substitute of our own Code of Cond...| Typelevel
This is a guest post by Chris Okasaki. It was initially published as the design document behind scads. It is being republished here with the permission of the original author. A heap (or priority queue) is a collection of elements ordered by some Ordering, optimized for retrieving the first element according to that ordering. Duplicate elements are allowed. Applications vary in whether they need the first element to be the smallest or the biggest element according to the ordering, so both var...| Typelevel
This is the second of a series of articles on “Monadic EDSLs in Scala.” Perhaps the most direct way to start writing an EDSL is to start writing functions. Let’s say we want a language for talking about sets of integers. trait SetLang { def add(i: Int, set: Set[Int]): Set[Int] def remove(i: Int, set: Set[Int]): Set[Int] def exists(i: Int, set: Set[Int]): Boolean } This works… to the extent that we want only to work with scala.collection.Sets. As it stands we cannot talk about other se...| Typelevel
It is our pleasure to announce that the Scala Center Advisory Board has invited us to nominate a member of the Typelevel community to serve as a community representative, alongside Bill Venners. To figure out whether or not we should accept this offer and who we pick we have held an open discussion on GitHub, resulting in my nomination, which I happily accept. Thanks everyone for their trust! The corresponding Scala Center announcement can be found here. On a more personal note: Some years ag...| Typelevel
ScalaCheck is a well-known property-based testing library, based on ideas from Haskell’s QuickCheck. It is also a Typelevel project. In this post, I’d like to show some of the underlying mechanisms, stripped down to the bare minimum. Testing with properties is well-understood in academia and widely used in parts of the industry – namely the parts which embrace functional programming. However, the design space of property-testing libraries is rather large. I think it is high time to talk...| Typelevel
Update: A comprehensive version of this blog post was published at the 2017 Scala Symposium and is available for free through the ACM OpenTOC service. The corresponding talk can be found here. The common encoding of type classes in Scala relies on subtyping. This singular fact gives us a certain cleanliness in the code, but at what cost? Problem Consider the following hierarchy of type classes. A similar hierarchy can be found in both Cats and Scalaz 7. trait Functor[F[_]] trait Applicative[F...| Typelevel
This is the first of a series of articles on “Monadic EDSLs in Scala.” Embedded domain specific languages (EDSLs) are a powerful tool for abstracting complexities such as effects and business logic from our programs. Instead of mixing ad-hoc error handling, database access, and web calls through our code, we isolate each domain into a little language. These little languages can then be used to write “mini-programs” describing, for example, how to create a web page for a user. Our prog...| Typelevel
When you use a type parameter to abstract over actual data in your ADT, there is typically only one variance that makes sense, if you choose to incorporate subtyping into your designs at all. This is the natural, “parametrically sound” variance. sealed abstract class MyModel[P, I, -T, +V] final case class Running[I, T, V]( run: (I, T) => V ) extends MyModel[String, I, T, V] final case class Inject[I]( config: I ) extends MyModel[Int, I, Any, Nothing] There are only four interesting possib...| Typelevel
As its opening sentence reminds the reader—a point often missed by many reviewers—the book Functional Programming in Scala is not a book about Scala. This [wise] choice occasionally manifests in peculiar ways. For example, you can go quite far into the book implementing its exercises in languages with simpler type systems. Chapters 1–8 and 10 port quite readily to Java [8] and C#. So Functional Programming in Scala can be a very fine resource for learning some typed functional programmi...| Typelevel
This is the ninth of a series of articles on “Type Parameters and Type Members”. Scala’s CanBuildFrom API is relatively well-founded and flexible; in combination with GADTs, it can provide that flexibility in a fully type-safe way, if users choose not to circumvent it with typecasting. However, it is designed in a purely mutable way; you cannot write a useful CanBuildFrom that does not rely on mutation, and you cannot use the API externally in a functional way. Let’s design an alterna...| Typelevel
As a result of LambdaConf’s decision to invite Curtis Yarvin as a speaker, the organizers of the Typelevel Summit Boulder have decided that affiliation with LambdaConf is no longer compatible with Typelevel’s goals, and we are cancelling the event, which was scheduled to happen on the Wednesday before the conference. Yarvin is an unapologetic proponent of bigotry. As a result of his modest celebrity in this regard, it is not possible for his views to be “left at the door.” By extendin...| Typelevel
Code should be reusable. An expression traversing a data structure shouldn’t be written multiple times, it should be pulled out into a generic traversal function. At a larger scale, a random number generator shouldn’t be written multiple times, but rather pulled out into a module that can be used by others. It is important that such abstractions must be done carefully. Often times a type is visible to the caller, and if the type is not handled carefully the abstraction can leak. For examp...| Typelevel
Scala’s type system allows us to annotate type parameters with their variance: covariant, contravariant, invariant. Variance allows us to define the subtyping relationships between type constructors – that is, under which conditions F[A] is a subtype of F[B]. Similarly in functional programming, there are covariant functors, contravariant functors, and invariant functors. The similarity in names is not coincidental. Covariance The common example is List[+A] which is covariant in its type ...| Typelevel
The work on the programme for the Philadelphia Summit is in full swing! As announced earlier, we’re happy to share with you the first batch of accepted talks. Don’t worry though, there’s still time until the end of the week to submit a proposal. Becoming a cat(s) person Want to contribute to Cats? Let’s head over to the Cats Issues list and do some live coding! Along the way we will see how the codebase is organized, the various bits of automation provided, and how you can use our var...| Typelevel
This is the eighth of a series of articles on “Type Parameters and Type Members”. You may wish to check out the beginning, which introduces the PList type we refer to throughout this article without further ado. When you start working with type parameters, nothing makes it immediately apparent that you are working with universal and existential types at the same time. It is literally a matter of perspective. I will momentarily set aside a lengthy explanation of what this means, in favor o...| Typelevel
While the CfP for the Philadelphia Summit is still open (have you submitted a proposal yet?), we can already announce our keynote speaker: Stephanie Weirich is a Professor at the University of Pennsylvania. Her research centers on programming languages, type theory and machine-assisted reasoning. In particular, she studies generic programming, metaprogramming, dependent type systems, and type inference in the context of functional programming languages. She is currently an Editor of the Journ...| Typelevel
Update: The summits are over, which means applying for assistance is not possible any longer. As it says in our code of conduct, we are dedicated to creating a harrassment-free, inclusive community of developers. We want to extend this philosophy to the Typelevel Summits in Philadelphia and Oslo by providing assistance and bursaries to help speakers and attendees who would otherwise not be able to join us. Bursaries for Speakers and Attendees We are approaching sponsors and commercial partner...| Typelevel
We have a big announcement to make. In 2016, there will be not just one, but two Typelevel Summits. Also, we’ve updated our website to include an up-to-date list of Typelevel projects. There’s been much work behind the scenes which we will talk about in a later post, so stay tuned! But first, here are some details about the Summits. Typelevel Summit US The first Typelevel Summit will be co-located with the Northeast Scala Symposium in Philadelphia. As Brian Clapper already announced on Tw...| Typelevel
This is the seventh of a series of articles on “Type Parameters and Type Members”. You may wish to start at the beginning; more specifically, this post is meant as a followup to the previous entry. However, in a first for this series, it stands on its own, as introductory matter. A program is a system for converting data from one format to another, which we have endowed with the color of magic. In typed programming, we use a constellation of types to mediate this transformation; a functio...| Typelevel
This post is an introduction into how operators are implemented in Cats and has been originally published in August 2015. Some more details can be found in the previous post. One of the simplest and most recognizable type classes is the semigroup. This type class abstracts over the ability to combine values of a certain type in an associative manner. What does associativity mean? We call an operation $\oplus$ associative, if for all $a$, $b$ and $c$, $a \oplus (b \oplus c) = (a \oplus b) \opl...| Typelevel
This article is about machinist, a stand-alone project which started out as part of the spire project and has been originally published in October 2014. The original description can be found on this blog. You should read that linked post first if you are not familiar with how Machinist works. Introduction Machinist Issue #2 asks: Is it correct, that this stuff is completely obsolete now due to value classes or are there still some use cases? An example of using value class for zero-cost impli...| Typelevel
This is the sixth of a series of articles on “Type Parameters and Type Members”. If you haven’t yet, you should start at the beginning, which introduces code we refer to throughout this article without further ado. In a subtyping language such as Java or Scala, first-class existentials are a helpful ally for modeling values and methods that abstract over subtypes in different ways. In a language with mutation, such as Java or Scala, existentials help deal with certain kinds of state cha...| Typelevel
This is the fifth of a series of articles on “Type Parameters and Type Members”. If you haven’t yet, you should start at the beginning, which introduces code we refer to throughout this article without further ado. Let’s consider a few values of type MList: val estrs: MList = MCons("hi", MCons("bye", MNil())): MList.Aux[String] val eints: MList = MCons(21, MCons(42, MNil())): MList.Aux[Int] val ebools: MList = MCons(true, MCons(false, MNil())): MList.Aux[Boolean] Recall from the first...| Typelevel
This is the fourth of a series of articles on “Type Parameters and Type Members”. If you haven’t yet, you should start at the beginning, which introduces code we refer to throughout this article without further ado. In the absence of the Aux trick presented at the end of the previous article, the continuous use of structural refinement to accomplish basic tasks admittedly imposes a high cognitive load. That is to say, it’s a lot of work to say something that ought to be very simple. S...| Typelevel
This is the third of a series of articles on “Type Parameters and Type Members”. If you haven’t yet, you should start at the beginning, which introduces code we refer to throughout this article without further ado. As I mentioned in the previous article, the error of the mdropFirstE signature, taking MList and returning merely MList, was to fail to relate the input element type to the output element type. This mistake is an easy one to make when failure is the default behavior. By contr...| Typelevel
This is the second of a series of articles on “Type Parameters and Type Members”. If you haven’t yet, you should start at the beginning, which introduces code we refer to throughout this article without further ado. In the last part, we just saw two method types that, though different, are effectively the same: those of plengthT and plengthE. We have rules for deciding when an existential parameter can be lifted into a method type parameter—or a method type parameter lowered to an exi...| Typelevel
This is the first of a series of articles on “Type Parameters and Type Members”. Type members like Member class Blah { type Member } and parameters like Param class Blah2[Param] have more similarities than differences. The choice of which to use for a given situation is usually a matter of convenience. In brief, a rule of thumb: a type parameter is usually more convenient and harder to screw up, but if you intend to use it existentially in most cases, changing it to a member is probably...| Typelevel
While this blog is typically strictly for Scala developers interested in strongly-typed programming, this particular article is of interest to Java developers as well. You don’t need to know Scala to follow along. Scala makes a welcome simplification in its type system: type arguments are always required. That is, in Java, you may (unsafely) leave off the type arguments for compatibility with pre-1.5 code, e.g. java.util.List, forming a raw type. Scala does not permit this, and requires you...| Typelevel
One of the rules of the Scalazzi Safe Scala Subset is “no type casing”; in other words, testing the type via isInstanceOf or type patterns isn’t allowed. It’s one of the most important rules therein for preservation of free theorems. Common functional programming practice in Scala seems to violate this rule in a subtle way. However, as we will see, that practice carves out a very specific exception to this rule that, morally, isn’t an exception at all, carrying convenient advantages...| Typelevel
We’ve previously seen the basic implementation and motivation for scalaz.Leibniz. But there’s still quite a bit more to this traditionally esoteric member of the Scalaz collection of well-typed stuff. Strictly necessarily strict The word “witness” implies that Leibniz is a passive bystander in your function; sitting back and telling you that some type is equal to another type, otherwise content to let the real code do the real work. The fact that Leibniz lifts into functions (which ar...| Typelevel
tl;dr Typelevel is forking Scala; we call on all stakeholders in the Scala ecosystem to collaborate on the creation of an independent, non-profit, open source foundation to safeguard the interests of the entire Scala community. Last week I tweeted the following question: How much interest would there be in a community sponsored fork of the #Scala toolchain? RTs and fav's please. — Miles Sabin (@milessabin) August 25, 2014 It generated a lively response, both on Twitter and privately. The re...| Typelevel
Also, the “fake covariance” trick. Sometimes, Scala programmers notice a nice optimization they can use in the case of a class that has an invariant type parameter, but in which that type parameter appears in variant or phantom position in the actual data involved. =:= is an example of the phantom case. sealed abstract class =:=[From, To] extends (From => To) with Serializable scala.collection.immutable.Set is an example of the covariant case. Here is the optimization, which is very simil...| Typelevel
The Scala standard library provides evidence of two types being equal at the data level: a value of type (A =:= B) witnesses that A and B are the same type. Accordingly, it provides an implicit conversion from A to B. So you can write Int-summing functions on your generic foldable types. final case class XList[A](xs: List[A]) { def sum(implicit ev: A =:= Int): Int = xs.foldLeft(0)(_ + _) } That works because ev is inserted as an implicit conversion over that lambda’s second parameter. Fra...| Typelevel
Scalaz used to have a scalaz.Functor for scala.collection.Set but it was eventually removed because it relied on Any’s == method. You can read more about why Functor[Set] is a bad idea at Fake Theorems for Free. If Set had been truly parametric, we wouldn’t have been able to define a Functor in the first place. Luckily, a truly parametric Set has recently been added to Scalaz as scalaz.ISet, with preliminary benchmarks also showing some nice performance improvements. I highly recommend us...| Typelevel
Consider the simple cons-list datatype. import scalaz.Equal, scalaz.std.option._, scalaz.syntax.std.option._, scalaz.std.anyVal._, scalaz.std.function._, scala.reflect.runtime.universe.reify sealed abstract class XList[A] final case class XNil[A]() extends XList[A] final case class XCons[A](head: A, tail: XList[A]) extends XList[A] And a simple function over this structure. Say, a simple summing function. def sum(xs: XList[Int]): Int = xs match { case XNil() => 0 case XCons(x, xs) => x + sum(...| Typelevel
Scalaz avoids variance in the sense of the Scala type parameter annotation, with its associated higher-kind implications, except where it has historically featured variance; even here, variance is vanishing as unsoundness in its released implementations is discovered. There is a deeply related concept in Scalaz’s typeclasses, though: covariant and contravariant functors. Functor is traditional shorthand for covariant functor, whereas Contravariant represents contravariant functors. These co...| Typelevel
Scala has several ways to deal with error handling, and often times people get confused as to when to use what. This post hopes to address that. Let me count the ways. Option People coming to Scala from Java-like languages are often told Option is a replacement for null or exception throwing. Say we have a function that creates some sort of interval, but only allows intervals where the lower bound comes first. class Interval(val low: Int, val high: Int) { if (low > high) throw new Exception("...| Typelevel
When working with implicit-encoded dependent function types, such as scalaz.Unapply and numerous Shapeless operations, you’d frequently like to acquire instances of those functions to see what types get calculated for them. For example, ++ on Shapeless HLists is driven by Prepend: def ++[S <: HList](suffix : S)(implicit prepend : Prepend[L, S]) : prepend.Out = prepend(l, suffix) So given some HLists, we can expect to be able to combine them in a couple ways. First, by using the syntax funct...| Typelevel
A lot of people see Scalaz as a hard fringe, ivory tower, not suited for real-world applications library, which is unfortunate. The goal of this blog post series is to introduce various components of Scalaz, and hopefully through this allow folks to gain an understanding towards the power of Scalaz. As a prerequisite, I assume knowledge of type classes as they are implemented and used in Scala, higher kinded types, and sum types (e.g. Option/Some/None, Either/Left/Right). For a tutorial/revie...| Typelevel