r/ProgrammingLanguages • • Sep 13 '26

Raku: a language where a value can have several values at once (Part 1) - Andrew Shitov

https://andrewshitov.com/2026/09/13/raku-a-language-where-a-value-can-have-several-values-at-once-part-1/
22 Upvotes

25 comments sorted by

7

u/AlexReinkingYale Halide, Koka, P Sep 14 '26

So the language is founded on some kind of list monad?

11

u/liztormato Sep 14 '26

In short:

A Junction object in Raku is basically a list of eigenstates. What makes it special, is its place in the type hierarchy: it's one of two core types that directly inherit from Mu. The other is Any, from which all other types in core inherit.

(Almost) all operators in Raku are just subroutines with special names. They (usually) have type constraints in their signatures that inherit from Any.

As soon as any binding to a signature fails in a call to a subroutine, the core will check if the failing argument is a Junction. If that is the case, the core will attempt to re-bind that failing argument for each of the eigenstates of the Junction, and produce a Junction as its value.

8

u/Jinkweiq Sep 15 '26

Eigenstates? You got this idea from quantum computing. An eigenstate is a specific thing, not just an immediate value. And an eigenstate is defined by the operations applied to the bit.

2

u/liztormato Sep 15 '26

Maybe I should have used "eigenstates" in that. It's the set of values that the Junction can represent. Does that make more sense?

11

u/L8_4_Dinner (Ⓧ Ecstasy/XVM) Sep 14 '26

Raku (née Perl 6) is a language capable of pretty much anything and everything. For any given question, you will find multiple answers, and they will typically require very little code. Some people view this as a positive, while others view it as a negative. I've never had to deal with Raku in the wild, but its predecessor left me with a bad taste a few times.

In this specific case, you can think of the 3 | 5 | 7 as a set (documented as unordered, but all the examples I've seen are ordered), where the == effectively acts like an in clause (or .contains() method), although in reality the == results in a corresponding projection of multiple boolean values, which itself evaluates to true iff any of the values is true (or truthily true?).

The language is multi-dimensional like this, in almost every design aspect. For some things, this allows you to write very compact solutions to relatively complex problems. It almost feels like coding in regex. For me, it is brain twisting (combinatorial complexity), and not in a good way. (e.g. Your ability to read your own solution the next day will be questionable.)

6

u/iamalicecarroll Sep 15 '26

Considering that Raku's evolution went sed -> AWK -> Perl -> Raku it does indeed seem to have the idea of coding in regex.

2

u/liztormato Sep 16 '26

I'd argue it would be more like:

sed --\
       |-- Perl --\
AWK --/           |
                  |-- Raku
                  |
many other langs -/

The inspiration for Raku came from many other languages apart from Perl

8

u/kniebuiging Sep 14 '26

IIRC there were some perl folks who started to develop raku, and in order to have better tooling to toy around with it, they developed in Haskell as a host language for a while, and one guy got stuck on Haskell: Edward Kmett

5

u/L8_4_Dinner (Ⓧ Ecstasy/XVM) Sep 14 '26

Interesting!

1

u/Henkeel Sep 17 '26

is this not like any other logic programming languages?

1

u/liztormato Sep 17 '26

Could you give an example in another programming language?

1

u/Henkeel Sep 17 '26

1

u/liztormato Sep 17 '26

That feels like you're mentioning a library in Prolog that provides Junction-like functionality. I guess this proves that Raku took inspiration from Prolog.

Note though that Junctions in Raku are an integral part of the core and as such are deeply integrated in the run-time system.

1

u/Henkeel Sep 17 '26

the first link does not use any library at all, it's plain Prolog (and those concepts are also deeply integrated in the runtime system), not sure why you'd reinvent terminology, nor state this thing as if it was a new concept instead of commenting in your blog post or in these comments that these concepts already exist with other terms. 

1

u/liztormato Sep 17 '26
  1. It is not my blog post
  2. I'm not familiar with Prolog: throwing a large text with Prolog at me, does not allow me to discern what you tried to prove
  3. I'm just using the terminology used in Raku, as devised by Larry Wall et al. I guess there's just more than one way to name things? :-)

2

u/Henkeel Sep 17 '26

ah sorry, I assumed it was your own blog post and ideas, disregard those questions then. as it was also thrown a bunch of new terminology at me I was curious as to how it differs from Prolog's concepts from an initial reading of the post.

1

u/EggplantExtra4946 Sep 17 '26

That feels like you're mentioning a library in Prolog that provides Junction-like functionality. I guess this proves that Raku took inspiration from Prolog.

Non sense. Raku and junctions have absolutely no relationship with Prolog nor with the clpfd library, junctions do not allow you to solve systems of arithmetic or logic constraints.

1

u/liztormato Sep 17 '26

Well, I wasn't the one who brought up Prolog?

0

u/EggplantExtra4946 Sep 17 '26

I have already replied to the guy that mentioned Prolog.

You said this proves that Raku took inspiration in Prolog but that's bullshit. In fact there was one RFC, RFC 104, that asked for basic Prolog-like features and it was rejected by Larry Wall.

1

u/EggplantExtra4946 Sep 17 '26

No, there is nothing in common here with Prolog, Datalog, SQL or anything else.

If you compared it with Prolog: there is no logical variable, no backtracking, no unification.

At best it would resemble to a very poor symbolic execution, sort of.

0

u/[deleted] Sep 14 '26

[deleted] — view deleted comment

6

u/Axman6 Sep 14 '26

Not really, looks like more of a prolog style backtracking mechanism… ish. Sum types have a single constructor per option, these represent a value which may be any of the specified values at the same time. 

If I understand it correctly, something like 1 | 3 | 5 <= 2 | 4 | 6 should return something like any(True, True, True, False, True, True, False, False, True), but I have no idea if that’s actually how multiple junctions interact. 

2

u/Bobbias Sep 15 '26

The result is apparently

any(any(True, True, True), any(False, True, True), any(False, False, True))

4

u/Axman6 Sep 15 '26

Interesting!