Abstracting over arithmetic

This blog post will deal with an experimental approach to higher order functions at compile time, at the type level. It’s motivated in part by my previous post on ternary Nat, Counting to Infinity at Compile time.

You needn’t understand the details of TNat (or its binary cousin BNat), just…

Higher better faster longer

We saw in a previous blog post of mine an introduction to counting at compile time in scala, using the conventional Nat type.

Unfortunately, Nat is slow. Really, really slow, and there are hard limits on what we can make the scala compiler do, as it currently stands.

For example…

Counting at compile time is one of the world’s simple pleasures. We have taken the scala compiler and hacked something in to it to make it do things it really doesn’t look like it should be doing.

The standard approach of ‘counting at compile time’ utilises a type commonly called…

In a previous blog post I introduced the scala library Alphabet Soup, for type-level transformations.

It provides a mapping between arbitrarily nested types, provided the compiler can calculate a path between them, all powered with gratitude by Generic from shapeless.

A quick example:

Target here could be any combination…

The library alphabet-soup can be found here.

Alphabet-soup is a scala library to provide faster compiler-time type-mixing, to reduce boilerplate and the cognitive overhead of reading and writing canonical code.

If there’s only one way to write a piece of code, why do we have to write it? …

Using free monads to control the execution of asynchronous tasks in Scala

This blog post will assume terminology from the functional scala library Cats. It is easily applicable to Scalaz, too.

Libraries like Cats and Scalaz give you a verb ‘traverse’, for easier handling of combinations of wrapper types.

It allows you to turn something clunky like this:

into this:

Escaping Union type contexts safely

Goal and ideal syntax

In a previous blog post I introduced a way to get unboxed arbitrary arity union types in scala. We can write

foo allows an Int or a String to be passed to it, and nothing else.

But escaping the union context, ie getting the Int or the String out…

How to pass sorting all the way through your Scala/Slick stack

When writing our project, we wanted to pass a static sorting object all the way through our stack from the API (where it was parsed automatically) to Slick, and have the database results be sorted automatically without any extra input from the end-user (ie you, the feature-developer).

(In this post…

Preventing `data-too-wide’ SQL exceptions in Scala

Most strings that you store in a traditional SQL database have a maximum length allowed. This can frequently cause problems, since this maximum length isn’t known by your code.

You might have some checks dotted around, maybe on your API or DB layer, that only sensible length strings get into…

James Phillips

Functional developer, typelevel enthusiast https://www.typechecked.io

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store