Tag: functional programming

Lambda World 2024

It was 2019 and nothing suggested that 2020 would not have been another regular year – another spring, another early bird ticket for the Lambda World conference, another regular summer, and then the most awaited conference of the year, a journey to Cadiz to attend Lambda World 2020.

Things went quite differently (for those reading from other planets – because of the pandemic) and the world was suddenly locked down, some conferences went online, and some were canceled, Lambda World included. Things went a bit better in 2021, but no news about a new edition of the functional programming conference. It was 2022, and many conferences had returned to the in-presence format, maybe with some precaution, but the worst part of the pandemic was finally over. Again no trace of Lambda World. 2023 came and went, and still no sign of lambda-life from Cadiz. Still vague or no answer to my emails to the organizing company.

And then suddenly and unexpectedly, the email popped up in my incoming folder – early bird ticket sale for Lambda World 2024 is open. I was so happy they were back, but at the same time I was about to change jobs and it was not the best approach to arrive on the first day at the new workplace and pretend to be sponsored to attend the conference. So, after a brief family check, I decided to self-sponsor my attendance and hope for at least some partial refund.

Continue reading “Lambda World 2024”

Fun with Functors in C

C language is old, actually, a very old language that resisted all the innovations that impacted the software development industries. Even ISO standard Cobol integrated object-oriented capabilities in 2002!

This didn’t prevent programmers from applying object-oriented programming to C. With some macro juggling and a lot of self-control not to break framework rules, you can have inheritance and dynamic dispatching.

Generic programming is, in the same way, foreign to C language1. You can use preprocessor macros to implement generic containers or functions that can be instantiated on the type you need, but it is a painful endeavor.

Continue reading “Fun with Functors in C”

What Happens in Monads Stays in Monads

There are moments in life when you have to take a stance. You know countless people already tried and possibly succeeded in doing something, but you feel the urge to try it yourself.

So yesterday I attended the Milan C++ Meetup by Marco Arena, presented in a very entertaining and well-organized way, what’s new in C++23. Everything was fine until Marco presented the std::expected template and its “monadic operations”. Now it was in the context of a much wider presentation and there was no time to go into details, but I got the impression that the C++ community has a bit of an ad-hoc approach to monads. I mean C++98 failed to recognize that containers are monads, C++11 failed to recognize that std::future is a monad, C++17 failed to recognize that std::optional is a monad, and C++20 failed to recognize that coroutines are monads. You can see a pattern there.

Continue reading “What Happens in Monads Stays in Monads”

Scala Italy 2023 – Scala Blues

It was 2015 when I attended my first Scala Italy conference. I was freshly landed in the functional programming magic world and I was tasked by my boss to asses whether Scala was a technology with a future or just a fade. I sat there, as proved by the picture used over the years as a background for the conference website, and enjoyed the show.

The conference was well organized, with a bunch of sponsors and some hundred people attending. My report, reinforced by attending Scala Days 2016 in Berlin, was that Scala was viable with quite a strong interest and support from the industry.

Over the years the conference grew, I missed the Venice edition in 2016, but I was in Rome in 2017, Florence in 2018, and eventually Bologna in 2019. Both Florence and Bologna were two-day events.

Continue reading “Scala Italy 2023 – Scala Blues”

Unfrightening Catamorphism and Anamorphism

TIL what Catamorphism and Anamorphism, and about a new useful function. Functional programmers are not shy to use mathematical terms that could frighten the casual programmer listening. Functor, monoid, applicative just to name the first that comes to mind. Usually, they turn out to be relatively simple concepts (which get combined together until they are no longer simple).

Continue reading “Unfrightening Catamorphism and Anamorphism”

Lambda Headache for Mere Mortals

A few years ago I attended a talk at a Lambda World Conference about Lambda Calculus. Although not an eye-opener (in fact that level of abstraction is rarely needed, nor advisable, in everyday programming), it was thought-provoking. By wisely crafting mathematical functions you could describe algorithms, fully equivalent to the good old recipe-like imperative programming code.

The point is that those lambda functions are really twisted.

Reading some anecdotes about Alonzo Church it is immediately clear he was quite a guy. And devising lambda calculus required quite a mind.

Since lambda calculus is just functions, no statement, it came to my mind I could use it to devise a solution to my “if-less” programming quiz.

The solution I prepared was too complex to be explained in my previous post, so I decided to write this post.

Continue reading “Lambda Headache for Mere Mortals”

Dealing with Errors in C++ Using a Lightweight Monadic Approach

Managing errors and failures in every programming language is usually a pain. Most programming book authors just show the happy path scenario, sometimes noting down that error handling has to be done, but it has been left out for improving simplicity (and readability).

C++ offers the exception mechanism, which is a clever way to leave the happy path in sight and hide the troubles under the carpet. Even before questioning if this is a good idea or not, C++ abstraction is so delicate that you need to take particular care in making your code exception-safe. Meaning that in case of exception, your program does not leak resources and leaves everything in a useful state so that the exception can indeed be recovered from.

Continue reading “Dealing with Errors in C++ Using a Lightweight Monadic Approach”

What’s wrong with you, std::optional?

“He Who Laughs Last Is At 300 Baud”, is possibly a long-forgotten joke, but sometimes C++ standard is like using a 300 baud modem, discovering “innovations” tens of years after other less committee-centric languages discover and apply them.

Let’s take the std::optional which tries to mimic the Option monad available in other languages. Since 1990 there has been a resurgence of functional programming languages in the mainstream – Haskell (1990), and Scala (2004) just to name two that have Option since their first version.

Continue reading “What’s wrong with you, std::optional?”

As Smart as a Smart Type – Practice (C++)

In theory, practice and theory are the same, in practice they are not. So, after having read how brilliant and smart smart-types are, it is now time to have a closer look at the compiler and figure out what C++ can offer.

After my last post, I found that Smart Types are also known as Refined (or refinement) Types. And here is a notable implementation for Scala.

Simple things first, if you need a type with a bunch of possible values, don’t use int & #defines, don’t use bool either (please), use enum, or, even better enum class.

Now that we’ve done with the trivialities, let’s proceed to something more challenging – numeric types. Ideally, we want some template code that wraps the numeric type and saves us the boredom of writing all the usual +, -, *, /, ==, !=, <… operators, while letting us define the rules of the existence of the represented type.

Continue reading “As Smart as a Smart Type – Practice (C++)”