For a long time, Scala has supported a useful “trick” called infix operator notation. If a method takes a single argument, you can call it without the period after the instance and without parentheses around the argument. This post describes changes in Scala 3.
For example, if I have a Matrix
class and a +
method to add matrices, element by element, I can write matrix1.+(matrix2)
or use the less cluttered and more intuitive syntax, matrix1 + matrix2
. The intention was to support true operators, like +
in intuitive contexts like this. …
Type lambdas are the type analog of “value lambdas”, also known as functions 🤓. This post explores them. The discussion naturally leads to the new ability to parameterize the types of functions, which was previously only supported for methods. While I’m at it, I’ll mention another method feature that’s now supported for functions, dependent function types.
March 8, 2021: Updated the Functor example after helpful feedback from Sergei Winitzki.
You can start reading the rough draft of Programming Scala, Third Edition on the O’Reilly Learning Platform. Most of the chapters are available. Feedback is welcome!
Let’s suppose we wanted to…
(With apologies to Bob Dylan.)
This post covers how some uses in Scala 2 of the underscore, _
, are being replaced with alternatives. The contexts include import and the new export statements and type parameter wild cards. Along the way, I’ll discuss other changes for import statements, the new export statement, and a syntax change for repeated parameter lists (a.k.a., variable argument lists).
Scala 3.0.0-RC1 is out! This means the language changes should be done. The discussion of import syntax changes below was the last major change. …
This post discusses a few changes and additions in Scala 3 that make designing robust, object-oriented type hierarchies a little easier.
Join me for Scala Love in the City, February 13th. I’m doing a talk about Scala 3’s contextual abstractions.
For an even more concise summary of most of the notable changes in Scala 3, see my new Scala 3 Highlights page.
You can start reading the rough draft of Programming Scala, Third Editionon the O’Reilly Learning Platform. The first half or so of the chapters are available. I am refining them still, but any feedback is welcome!
While object-oriented…
Let’s take a break from the type system changes and discuss other new features in Scala 3. This post is about universal apply methods, which eliminate the need for using new
when creating instances, most of the time.
For an even more concise summary of most of the notable changes in Scala 3, see my new Scala 3 Highlights page.
You can start reading the rough draft of Programming Scala, Third Edition on the O’Reilly Learning Platform. The first half or so of the chapters are available. I am refining them still, but any feedback is welcome!
One of the…
In the last post (which proved popular), I introduced dependent types and discussed interesting things you can with values as types, like val onePlusOne: 1+1 = 2
. In this post, I’ll visit some more sophisticated capabilities provided by dependent typing.
January 17, 2021 update: Chris Birchall pointed out to me that it’s not necessary to use
NSize[N]
in theDTList
example.N
will do. I added another recursive type onN
example instead.
For an even more concise summary of most of the notable changes in Scala 3, see my new Scala 3 Highlights page.
Scala 3 expands on the type-level computing you can do at compile time. This post starts a discussion of dependent types.
Happy New Year! I hope 2021 is better than 2020 for all of us.
For an even more concise summary of most of the notable changes in Scala 3, see my new Scala 3 Highlights page.
You can start reading the rough draft of Programming Scala, Third Edition on the O’Reilly Learning Platform. The first half or so of the chapters are available. I am refining them still, but any feedback is welcome!
Dependent types are types that depend…
Two new features in Scala 3’s type system are intersection and union types. They embrace set theory more explicitly to improve the soundness of the type system, where a type can be considered a set and the instances of it are the members of the set.
December 29, 2020 and January 7, 2021. Fixed mistakes in the discussion of subtyping for intersection types and the distribution laws. Thanks to James Warren , Sean Kim, and Pascal Mengelt for catching my mistakes.
For an even more concise summary of most of the changes in Scala 3, see my new Scala 3…
In this post, I begin a tour of many of the changes to Scala’s type system in Scala 3. Let’s start with two relatively small changes, opaque type aliases and open classes, which have nice properties for better performance and better code quality.
December 4, 2020: Clarified the tradeoffs between value classes and opaque type aliases, following comments by Martin Odersky in a contributors mailing list thread.
It’s common to have small classes that represent domain concepts and operations, but are backed by a single AnyVal
, like a Double
. In some cases, you really want the performance of having just…
In my last post, before the revolution, I discussed the Scala 3 way of defining type classes.
Update, November 18, 2020: I added new information about importing given instances.
Update: December 27, 2020. The syntax for given instances and extension methods was refined slightly in Scala 3.0.0-M3.
This post finishes this quick overview of contextual abstractions with a discussion of the new using clauses that replace implicit parameter lists.
But first, Scala 3 reached its first milestone release this past week, Scala
3.0.0-M1
. The book examples now use it. …
The person who’s wrong on the Internet. ML, AI, & FP supplicant at Domino Data Lab. Formerly at Anyscale and Lightbend. Speaker, Lover, O’Reilly author.