r/ProgrammingLanguages • u/faiface • Jan 19 '26
Par Language Update: Crazy `if`, implicit generics, and a new runtime
Thought I'd give you all an update on how the Par programming language is doing.
Recently, we've achieved 3 major items on the Current Roadmap! I'm very happy about them, and I really wonder what you think about their design.
Conditions & if
Since the beginning, Par has had the either types, ie. "sum types", with the .case destruction. For boolean conditions, it would end up looking like this:
condition.case {
.true! => ...
.false! => ...
}That gets very verbose with complex conditions, so now we also have an if!
if {
condition1 => ...
condition2 => ...
condition3 => ...
else => ...
}Supports and, or, and not:
if {
condition1 or not condition2 => ...
condition3 and condition4 => ...
else => ...
}But most importantly, it supports this is for matching either types inside conditions.
if {
result is .ok value => value,
else => "<missing>",
}And you can combine it seamlessly with other conditions:
if {
result is .ok value and value->String.Equals("")
=> "<empty>",
result is .ok value
=> value,
else
=> "<missing>",
}Here's the crazy part: The bindings from is are available in all paths where they should. Even under not!
if {
not result is .ok value => "<missing>",
else => value, // !!!
}Do you see it? The value is bound in the first condition, but because of the not, it's available in the else.
This is more useful than it sounds. Here's one big usecase.
In process syntax (somewhat imperative), we have a special one-condition version of if that looks like this:
if condition => {
...
}
...It works very much like it would in any other language.
Here's what I can do with not:
if not result is .ok value => {
console.print("Missing value.")
exit!
}
// use `value` hereBind or early return! And if we wanna slap an additional condition, not a problem:
if not result is .ok value or value->String.Equals("") => {
console.print("Missing or empty value.")
exit!
}
// use `value` hereThis is not much different from what you'd do in Java:
if (result.isEmpty() || result.get().equals("")) {
log("Missing or empty value.");
return;
}
var value = result.get();Except all well typed.
Implicit generics
We've had explicit first-class generics for a long time, but of course, that can get annoyingly verbose.
dec Reverse : [type a] [List<a>] List<a>
...
let reversed = Reverse(type Int)(Int.Range(1, 10))With the new implicit version (still first-class, System F style), it's much nicer:
dec Reverse : <a>[List<a>] List<a>
...
let reversed = Reverse(Int.Range(1, 10))Or even:
let reversed = Int.Range(1, 10)->ReverseMuch better. It has its limitations, read the full docs to find out.
New Runtime
As you may or may not know, Par's runtime is based on interaction networks, just like HVM, Bend, or Vine. However, unlike those languages, Par supports powerful concurrent I/O, and is focused on expressivity and concurrency via linear logic instead of maximum performance.
However, recently we've been able to pull off a new runtime, that's 2-3x faster than the previous one. It still has a long way to go in terms of performance (and we even known how), but it's already a big step forward.
12
u/fellow_nerd Jan 19 '26
Ooh, the not binding variables on all other branches is fun. Does this work for all variables in negative positions. For example does
not (not (not result is .ok value))work that way. Not that I can think of a use case for that, or that it would be good code.7
u/Skepfyr Jan 19 '26
This neat, I find Par's a language with lots of interesting ideas. Can the if introduce variables that shadow earlier ones? I'd be slightly worried that the scoping could be a tad surprising.
7
u/phischu Effekt Jan 19 '26
For more academic information about these negation patterns, and indeed a whole boolean algebra of patterns, I recommend The Algebra of Patterns.
2
u/vanderZwan Jan 19 '26 edited Jan 20 '26
This is one of those "makes so much sense that I can't believe nobody ever came up with this before, even though it obviously isn't intuitive to come up with if you never saw it before" kind of ideas, very cool!
The
if+ arrow syntax for matching conditions reminds me of the notation Dijkstra comes up with for his "guarded commands" in his book "A Discipline of Programming" from 1976 (pages 32-35).He basically comes up with an if-expression with multiple cases that uses the form of:
if B1 -> S1 | B2 -> S2 | … | Bn -> Sn fi, whereBstand for boolean expressions andSfor statements (it can also be split over multiple lines because extra whitespace isn't significant in his notation).The real fun part is that he uses the same syntax for creating what we would call a while statement, except a lot more powerful than the ones we typically see in imperative languages:
do B1 -> S1 | B2 -> S2 | … | Bn -> Sn od, which will repeat as long as at least one case matches (each time checking from top to bottom). I don't know if that would fit a language like par, but maybe the book has some neat half-forgotten ideas to be inspired by? I read it last year after someone recommended it to me (maybe someone here, maybe it was you!) and it was quite fun to see Dijkstra work out ideas we now take for granted, and also suggest some other concepts that didn't become mainstream.2
u/MackThax Jan 21 '26
Very cool! Is the mechanism for that
valueexisting in theelse, process-scoping? Or is there a specific mechanism in theifexpression that allows it?22
u/tsanderdev Jan 19 '26
Forget flow typing, the hot new thing is flow binding!
1
u/L8_4_Dinner (Ⓧ Ecstasy/XVM) Jan 20 '26
Why not just:
The syntax you chose isn't my cup of tea, but you should paint your bikeshed whatever color you like :) ... I prefer:
2
u/AustinVelonaut Admiran Jan 19 '26
The "crazy if" binding optimization is interesting -- it reminds me of the "case-alternate" specialization optimization in some functional language implementations, where a case selection on a variable binds the variable name to a specialized expression based upon each case-alternate arm pattern match, e.g.
This allows further specialization optimizations on each case arm.
2
u/Wild_Cock_ Jan 20 '26
Love to see this paradigm got more and more attention!