Lambda Calculus in a typed world

Image for post
Image for post

Lambda Calculus is a “is a formal system in mathematical logic for expressing computation” based on the concept of functions and defined by Alonzo Church in 1936.

Alan Turing demonstrated that Lambda Calculus and Turing Machine are equivalent, and therefore that Lambda Calculus is Turing complete. This means that any computation can be performed using Lambda Calculus.

Some may feel that approaching Lambda Calculus with pen and paper can be difficult, very much abstract, tedious to work with.

The cool thing is that Lambda Calculus, as we said, is based on the concept of functions, which is something that programmers are very familiar with. And in fact we can implement Lambda Calculus with any programming language that supports “functions as first class citizens”, i.e. with any language where functions can be passed as parameters to other functions as well as returned as results from functions. …

For a rational choice we need to consider other more important elements.

I often happen to stump into posts comparing Java and Go. Almost always, at the center of the comparison is either the speed of execution or the presence/lack of specific features (usually absent in Go and well established in Java).

So if one writes that Go is awesome, there are tens of replies stating that Java is much better because “there is this benchmark that proves Java is much faster” (plus it has Generics and also try-catch). Then you read the “benchmark “that states that Java is faster than Go, and you find another flock of comments sustaining the opposite.

The tone tends to quickly drift towards that of a religious war. …

Forse oggi ci sono strumenti migliori di Java per sviluppare applicazioni su architetture moderne

Da qualche anno stiamo assistendo ad una sempre più estesa adozione delle architetture a Microservizi che si appoggiano su containers. In contesti IT di tipo tradizionale, spesso le troviamo utilizzate con un linguaggio di programmazione quale Java, nato nei primi anni ’90 e progettato per un mondo di applicazioni monolitiche (vi ricordate i cari vecchi Application Servers?).

A volte questa scelta è dettata da solide ragioni: necessità di integrare sistemi legacy tramite librerie presenti solo nell’ecosistema Java, convenienza ad utilizzare competenze già esistenti in azienda. …

The Sieve of Eratosthenes algorithm implemented using streams, recursively

Image for post
Image for post
The Sieve of Eratosthenes: prime numbers as stream

Prime numbers can be conceived of as an infinite stream of integers: 1, 2, 3, 5, 7, 11…etc.

More than 2.000 years ago, the Greek mathematician Eratosthenes discovered that prime numbers can be calculated using streams in a recursive way.

In this article we will see a couple of different implementations of such logic, one using RxJs and Typescript, the other using Go channels as streams.

“Sieve of Eratosthenes” With RxJs Observable Streams

To start our calculation we need to generate a stream of all integers, starting from 2, which is going to be the source used by the algorithm. …

Lambda functions and WebSockets — how the opposites meet in the cloud

Image for post
Image for post
Image credit: Author

Lambda functions and WebSockets can be seen as concepts difficult to reconcile. Lambdas are ephemeral by nature. They appear when invoked and then disappear sometime after they have finished working. WebSockets, on the contrary, maintain stable, long-living connections between one server and many clients.

The AWS APIGateway offers the possibility to bring these two things together, combining the advantages of the Lambda on-demand model with the power of WebSockets’ real-time bidirectional communication.

In this article, we describe how to implement a WebSocket server using AWS API Gateway and Lambda functions. …

Image for post
Image for post

Suppose you have to add a new major feature to an app. Which of the 2 scenarios is easier?

  • add the feature to a relatively small app, still under construction, not yet in production
  • add the feature to an app that has grown over time, whose overall quality is questionable, which is already running in production serving several clients

Well, there is no doubt. The second is a much more challenging task.

But then why do we usually find a more senior experienced team in the first and more junior teams buried in the second?

Many years ago

When I entered the team that was developing the new Payment system for a major European Bank, the first position I was given was in the Application Maintenance (AM) team responsible for the legacy parts. The reasons were simple and shared: I was new to the place, new projects were running fast using leading edge technologies for which there was not much experience. AM would have been the right place for me to grow without too much pressure. As soon as I had gathered enough knowledge and experience I would have moved to the Project team, the team developing new features with new technologies, the team of the cool people. After one year or so this actually happened, but I will never forget that supposedly not-so-stressful period of AM. …

Real-world scenarios from Stack Overflow

Image for post
Image for post
Image source: Author

Reactive programming is getting traction and so is the use of ReactiveX libraries. More and more people start using this paradigm and often face similar problems in their learning path. Similar problems call for similar solutions, and this is what patterns are.

An interesting source to understand real-life problems is Stack Overflow. I started looking at the questions around RxJS some time ago, and I’ve noticed some recurring themes and similar situations that people have to deal with.

One popular theme is around asynchronous API calls; in other words, how to deal with HTTP requests in the real world. …

Image for post
Image for post

Can you do recursion using only Javascript anonymous functions?

Certainly. Here the Factorial of a number in one line

const fact = x => (x === 0 ? 1 : x * fact(x - 1));

No, no. This is not anonymous. You name the function fact via a Javascript const and reference it within itself. I mean really anonymous, something like

(...params) => { // do stuff }

with no variables at all, no self references, no state, just pure functions. Can you do this?

Well, according to Lambda Calculus you can, using what are called Fixed-Point Combinators.

Let’s see them in action using real Javascript code. …

Image for post
Image for post
A market of Lemons or a market of Peaches?

Netflix Presentation — 2013.

One CTO of a Fortune 100 Company says:

“We can’t copy Netflix because it has all those superstar engineers, we don’t have the people”.

Adrian Cockcroft, at the time Cloud Architect at Netflix, gives a round look at the badges of the audience, and then replies:

“We hired them from you, and got out of their way”.

1970. After 3 unsuccessful attempts, George Akerlof publishes “The Market for Lemons: Quality Uncertainty and the Market Mechanism”. This paper will grant him Nobel Prize in 2001 and is still one of the most-cited in modern economic theory. Akerlof uses the example of the market of used cars to illustrate this basic concept: in a Market of goods of different quality where the seller has more information than the buyer about the quality of the goods sold, eventually the bad quality goods, Lemons in the used cars jargon, will expel the good ones, the Peaches in the same jargon. …

Image for post
Image for post


This is an article about Typescript and Functional Programming. It is not an article about Lambda calculus theory.

We will implement Lambda calculus in Typescript as a way to exercise Functional Programming. We will do this solving a simple problem using only Lambda calculus constructs.

In the end, maybe, also the basics of the theory may result clearer.

The problem and the language

The problem to solve is simple: if 2 numbers n and m are equal, then return n + m otherwise, return m — n.

But we have a language that allows us only to use the following construct

x => y  // anonymous function with 1 parameter (i.e. unary function)…


Enrico Piccinin

A man with passion for code and for some strange things that sometimes happen in IT organizations. Views and thoughts here are my own.

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