Tag: functional programming

Elf and Guards – Days 5 and 6

It couldn’t last forever—spending consecutive days writing about my progress in the Advent of Code took too much time and the rest of my life knocked on the door. In this post, I will try to update you quickly on days five and six.

On day 5 we had to assist an unfortunate handbook printer to get the updated pages in the correct order. Being magic-elven stuff, the proper order is not the natural increasing order of integers, but a custom order defined by number pairs – e.g. 43|12 means that page 43 has to be followed immediately by page 12. But stuff is not that simple, the order relationship is not linear like abc, but may branch, so to give you an idea, after a may come either b or d and then are both followed by c.

Continue reading “Elf and Guards – Days 5 and 6”

Finding XMAS – Day 4

Day 4 of the Advent of Code presents you with two new puzzles based on the word search puzzle idea. For some reason, you are teleported to the Ceres Elven Station (that made an appearance in AoC 2019), but there’s nothing for you to see here (yet) – not even the chief historian we looking for. So a small elf asks for your help to solve her word search.

Being Xmas elves the word you have to look for is “XMAS”, it can be written straight or reverse and can be written in any direction left, up left, up, up right, right down right, down and down left.

Continue reading “Finding XMAS – Day 4”

Elves’ Programming Language – Day 3

There are plenty of programming languages and, of course, Xmas elves have their own. Although your main goal is still to find the Chief Historian, we are now in a warehouse, historian minions are wandering around looking for their boss and we are tasked to fix the computer1.

This puzzle seemed a bit easier than the first two days, but I found it somewhat underspecified. You have to scan a text for patterns like “mul(n,m)” with n and m integers. For each pattern multiply n by m and sum all the products together.

Continue reading “Elves’ Programming Language – Day 3”

Elves’ Advent Quest – Day 2

After warming up with the first day’s puzzle, here we are with the second day. The bar is still low, but not as low as yesterday. With the coordinates decoded in the last puzzle, everyone runs to the nearest location which happens to be a nuclear plant (for reindeer needs). While we are here the elves running the plant ask for your help to analyze some data looking for anomalies.

Yes, we are in a hurry to look for the chief historian elf, but we also have 25 days to fill with puzzles. So here we go.

Continue reading “Elves’ Advent Quest – Day 2”

Helping Elves One Star at a Time

That period of the year has finally come. That cozy winter feeling of cold outside the window, while busy waiting for the holidays. As a long-standing tradition that started last year, this is the time I help Elves prepare for Xmas in the Advent of Code.

Each day of Advent, the Advent of Code, proposes a couple of puzzles that can be solved by writing some code. There are no constraints on the language or the approach since the result of the puzzle is an integer number. Also, there is no deadline, you can continue working on the puzzles after Xmas. And there is no prize, you just know you did the right thing helping the elves and Santa.

Continue reading “Helping Elves One Star at a Time”

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”