Until about 2022, I loved to program in Raku, the language formerly know as Perl 6. (Sadly, since then, genAI has ruined that for me.)
Raku has neat feature called Junctions. A junction is a lazy expression of values of any type combined with Boolean-like operators `|`, `&` and `^`. When an operation is applied to a Junction, it is carried out for each junction element, and the result is the junction of the return values of the operations. You can optionally evaluate a Junction in a Boolean context using `so`.
So you can do things like
my \jj = 1&2;
say so jj; # True
say so (->\x {x-1})( jj ); # False
Back in 2020 I pointed out an issue with Junctions, [The strange case of the greedy junction](https://limited.systems/articles/greedy-junctions/). Junctions are *greedy*, they turn anything they are combined with also into a Junction. This is not always desirable. I proposed an additional operation ("collapse") to undo this behaviour.
In a second post [Reconstructing Raku's Junctions](https://limited.systems/articles/reconstructing-raku-junctions/) I provided a proof for both the observed behaviour and the need for a "collapse" operation, by formalising Junction semantics in terms of polymorphic algebraic data types. I just re-read it and I still think it is very cool.
The `collapse` method never made it into the language (https://github.com/rakudo/rakudo/pull/3944) but my implementation still works.
What I think is neat is that my formalisation lets you implement Junctions in any language.
#programming #programmingLanguages
#rakulang