Here's a puzzle. Without looking at the body, what does this Rust function do? fn mystery < T > ( a : T ) -> T If you know a little type theory, you might already see it: this function must return a . Not by convention, nor by style guide: the type system makes any other implementation impossible. There is nothing else you can do with a value of an unknown type except give it back. This…
Over the Christmas holidays I decided to learn more about OxCaml , Jane Street's systems programming variant of the OCaml programming language. In this post I give an overview of OxCaml, describe how to get started using it, and discuss a simple example that shows the performance benefits from using one of its basic feature: unboxed types.
Of my recent projects, one of the most fun was creating an algorithm for generating unique identifiers. In this post I'll walk through my process, and show how a combination of mathematics, computer science, and business requirements lead to the solution. I found this a very interesting problem, and I think it makes a great case study of how theory and practice go together.
We recently wrapped up season six of ScalaBridge, with a review of the past season and a discussion of what we want to see next year. To be honest, entering the review I wasn't feeling optimistic about ScalaBridge's future. In the two years since resuming I feel we haven't found a structure that really works. Partly this is the environment we're in; everything is harder now than it was before…
When understanding programming language features, and explaining them to others, I've found it useful to have two different kinds of explanations. The first kind, which I call an operational explanation , explains a feature in terms of how the program executes. The second kind, which I call a denotational explanation , explains features in terms of what they mean to the programmer. For myself, and…
In this post we'll build a DSL for terminal interaction. The terminal is familiar to most programmers, and terminal applications are common for developer focused tools. Most terminal features are controlled by writing specially formatted text. However, applications benefit from higher-level abstractions, motivating libraries that present a more ergonomic interface. Our implementation will showcase…
Direct-style effects, also known as algebraic effects and effect handlers, are the next big thing in programming languages. They are already available in Unison and OCaml , are coming to Scala , and I'm seeing discussion about them in other closely-related-to-industry contexts . The goal is very simple: to allow us to write code in a natural style without monads, but still get the benefits of…
For the next edition of Scala with Cats I'm writing a section on implementing interpreters. In my research I ended up going fairly deep down the rabbit hole of optimizations, in which virtual machine dispatch is a major area. There are many different approaches to dispatch, and I struggled to relate them until I realized they were all variations on a basic structure that resulted from applying the…
ScalaBridge London is a community for learning Scala, for people who are underrepresented in technology. We last met in 2020, stopping when COVID made it impossible to continue. I want to restart ScalaBridge London. Here's the plan. If you'd like to take part, please signup .
Function programming is based; that is, based on principles that allow a systematic and repeatable process for creating software. In this post I'm going illustrate this process with an example of summing the elements of a list, inspired by this conversation . We'll mostly be looking at algebraic data types and structural recursion (which often uses pattern matching , but is not synonymous with…
In this article I'm going to go through the process of improving some code. I'm mentoring a new developer who is applying for their first job. They were asked to complete some tasks on Codility as the first step of the interview process. To get used to the platform they did the first example task, and I advised them on some changes. I'm writing up here the progression from their code to (what I…
"I was three when the elephants ate the house next door," opens a paragraph on page 108 of my copy of Enough , the new book by Dr Cassandra Coburn. It encapsulates a lot of what I like about this book: it deals with important issues but it's also a lot of fun.
Building an understanding of code is one of the main tasks in software development. Whenever we want to answer a question about code—what is this doing? why doesn't it work? how can we make it faster?—this is what we're doing. I have found it valuable to consciously surface the strategy I use to answer these questions, and have categorized my approaches into three groups: reasoning about code;…
I recently led a training session where we implemented the rules for scoring ten-pin bowling in Scala. It makes for a good case study. It’s small enough that you can pick up the rules in a few minutes, but the dependencies between frames makes calculating the score non-trivial. I decided to implement my own solution which turned into an interesting exercise in algebraic data and finite state…
The programming world is moving towards functional programming (FP). More developers are using languages with an explicit bias towards FP, such as Scala and Haskell, while object-oriented (OO) languages and their communities adopt FP features and practices. (A striking example of the latter is the rise of Typescript and React in the Javascript community.) So what is FP and what does it mean to…
Scala with Cats 2 is underway, with a fancy new website. Go and join the mailing list linked from the site if you want to keep up with the latest developments.
In preparation for a talk at NEScala I wrote this quick survey on the research on curriculum and pedagogy for teaching programming (curriculum means what we teach, and pedagogy is how we teach it). My goals are: give a framework for thinking about curriculum and pedagogy; give some specific tips for teaching programming; point out where I believe more research is needed. My survey is based on the…
In a previous post I discussed the steps needed to compile a http4s web service to an executable with GraalVM Native Image. . It's natural to ask what tradeoffs are made by going this route instead of using the JVM. In this post I present several benchmark results I obtained comparing the Native Image executable to the running on the JVM. Read on to find out which comes out on top!
A recent project has involved serverless web services in Scala, which led me to investigate using GraalVM's Native Image tool to create native executables. In this blog post I describe the steps necessary to build a native executable from a simple http4s web service. There is also complete code accompanying this example.
A few weeks ago we wrapped up season two of ScalaBridge London . (For us, a "season" is an intensive series of meetings over a short period of time. Season two was six meetings in six weeks, but we might change this in future.) Here I want to reflect on what---in my opinion---were the good and bad parts of this season, and discuss what happens next.
I would like to measure the effectiveness of ScalaBridge London , but this raises some tricky questions. For example, what does it even mean for ScalaBridge to be effective? I'm not sure. I'm writing this largely as a way to organise my thoughts, and share with others who may be able to help.
In an earlier post I described our first run of ScalaBridge London . Now I want to turn to the future and talk about lessons learned and what we're planning for the next run. Some of these plans are more concrete than others. One of the great things about ScalaBridge is we're learning as we do it, and almost everything is subject to change.
ScalaBridge aims to increase diversity within the Scala community by providing training in Scala to traditionally under-represented groups. ScalaBridge London is, as the name suggests, the London chapter of ScalaBridge. A month or so ago we finished the first "season" of ScalaBridge London. Now is a good time to reflect on what we did and how it worked out.
Gatsby is a Javascript framework for building static sites. It has the pernicious effect of infecting the browser cache, and won't go away until you manually clear the cache or deploy a file that kills it. Here I describe the problem and the solution.
Type classes and records of functions are two very similar tools that are available in languages like Haskell, Scala, and Rust. Given the similarity the question arises of which we should use. In this blog post I discuss when I think one language mechanism should be preferred over the other.
I recently gave a talk on teaching Scala. I first gave the talk at the Scala in the City meetup, which was a dry run for the version I gave at Scala Days . Take a look at my slides if this is of interest to you. My talk centered around five tips for teaching. Here I give a quick rundown of the tips and some references for further reading.
How do you write an abstract for a (industry) conference talk proposal? I like to use a three paragraph structure. The first paragraph gives a quick overview of what attendees can expect to learn if they attend the talk. The second paragraph gives motivation and background—why should attendees care about what I have to say? The third and final paragraph goes into more detail on the points I intend…
Last update: 15 February 2020 I recently switched to Doom Emacs from Spacemacs. The Doom documentation is currently quite sparse, so I've posted here my personal notes on using Doom along with a description of my workflow (something I find vital but missing from most documentation). Doom might be for you if you like Emacs but want to use Vim keybindings; you don't have time to configure all the…
This is a post about church and state, and how we can unite the two for a better world, while avoiding unfortunate side effects. Political metaphors aside, this really is a post about Church— Alonzo Church —and how we can use his idea of Church encoding to unite pure FP and imperative OO to achieve, if not a better world, at least better code.
The interpreter is the über pattern of functional programming. Most large programs written in a functional style can be viewed as using this pattern. Amongst many reasons, interpreters allow us to handle effects and still keep desirable properties such as substitution. Given the importance of interpreters it is not surprising there are many implementation strategies. In this blog post I want to…
At the Typelevel Summit in Philadelphia I gave a talk about probabilistic programming, which I have recently been exploring . Probabilistic programming combines two great research areas that go great together---functional programming and machine learning (specifically, Bayesian inference). In this blog post I'll attempt to explain the basic ideas behind probabilistic programming. I'm assuming you,…
At Scala Exchange 2015 I gave a workshop on building interpreters in Scala. Code and slides are here , though future development will take place here . The workshop covered untyped interpreters, GADTs, and ended with the free monad and free applicative.
I recently saw this image, taken from a maths test. The student has been asked to represent 5×3 in terms of repeated addition. They have written 5+5+5. The teacher has marked this as incorrect and given 3+3+3+3+3 as the correct answer. Like many people, when I first saw this I thought the teacher was clearly wrong. After a bit of thought I realised they were correct, and after still more thought I…
In a recent training course I was asked if Scala supports static or dynamic polymorphism. These are not terms I had heard before, so I had some homework to do. A bit of research showed this terminology refers to the same thing as early and late binding, which I'm more familiar with. So, here we have a quick discussion of early binding (or static polymorphism) and late binding (or dynamic…
A major theme of this blog is design principles for Scala code. In the past we've talked about Scala mechanics like sealed traits and general principles like simplicity in Scala . In this post I want to discuss a very general principle called reification and show its application in two different domains: monad composition and stream libraries like Akka Stream.
I recently wrote about keeping Scala simple . That's something you have to work at. Let me explain. While packing up to move house I came across my undergrad vector calculus notes. Although I, sadly, don't remember the definitions of div, grad, and curl I do remember that course as marking a turning point in my academic career.
In this post I want to explore the design of a type class solving a problem that came up repeatedly in my current project. It's fairly general, so rather than diving into the details of the project, I'll start with a few simple examples: integer multiplication is annihilated by zero, in that once zero is introduced the result is always zero; set intersection is annihilated by the empty set, in…
You don't have to venture far to find people arguing that Scala is a complex language, or that Scala needs to be more opinionated. Luckily I have plenty of opinions, specifically about how to make Scala simpler, and this is something I've been espousing in my recent talks at Scala Days SF and Amsterdam ( slides here ). The problem with talking about simplicity is that it becomes one of those…
You wouldn't think the Internet would need a an introduction to cats , but then this Cats is a Scala library, not a small furry bed-hogging mammal. Cats is the spiritual successor to Scalaz: a library of absolutely essential utilities you really want to be using in your Scala code. Compared to Scalaz, Cats is more modular and it is using some newer tools to make its code base easier to work with.…
My recent post on sealed traits had some great feedback but it was clear that I glossed over some points too quickly. In this post I want to go over a new trick I've learned for sealed traits and clear up some of the points I made in the last post.
Sealed traits are essential for idiomatic Scala code, but many developers are hazy on the details of their working. In this post we describe why you want to use them, and how to use them correctly to increase the quality of your code.
I spent last week at the rather ungainly titled Strata + Hadoop World London , O'Reilly's big data conference. I've attended the London event since it started in 2012 and it's been interesting to observe how the conference has changed over time. If I was to summarise the biggest difference from 2013, when I was last at Strata, it is that the field is growing up. The vendor hall was absolutely…
Understanding monads is a puzzle with many parts. Understanding the monad interface was easy enough for me, as I'd been programming in functional languages for a while when I first started exploring them, but for a long time I didn't understand how they made IO operations pure. The answer is to add an extra wrinkle, usually glossed over in Haskell oriented sources, by making all IO actions lazy.…
The free monad is defined by this structure: sealed trait Free [ F [_], A ] final case class Return [ F [_], A ]( a : A ) extends Free [ F , A ] final case class Suspend [ F [_], A ]( s : F [ Free [ F , A ]]) extends Free [ F , A ] We can use the free monad without understanding its implementation, but to really understand it we need to know why it is defined this way. It certainly wasn't obvious…
I recently gave a talk at the Advanced Scala meetup in London on free monads. Despite the name of the group, I think that free monads are eminently simple as well as being extremely useful. Let me explain.
I spent a few hours learning Shapeless and it made me $500. At ScalaDays 2014, Originate ran a competition to implement a simple stack-oriented (aka concatenative) language. The competition hit all three points on my "interesting competition" scoring metric: the subject matter is intrinsically interesting to me; I thought I could implement a basic solution quite quickly; and there were clear…
AngularJS and React are two of the most prominent Javascript UI frameworks today. It is natural to ask which is best. Having some experience with both my opinion is that React is superior by a large margin. I'll get into why in a moment, but first some background so you can understand how I came to this conclusion. I'm not very experienced with either framework. I have written some small projects…
We cannot rely on mass inspection to improve quality, though there are times when 100 percent inspection is necessary. As Harold S. Dodge said many years ago, 'You cannot inspect quality into a product.' The quality is there or it isn't by the time it's inspected. W. Edwards Deming Code reviews are a great tool for polishing good code into great code, but they aren't going to turn bad code to…