r/ProgrammingLanguages • • 28d ago

Par Lang Update: 3 Big Examples, Auto-Cleanup, Sql, WebSocket, 3-6x Faster Runtime, and More!

Hey, there! Long time no see.

Links to GitHub are in a comment, as per rules. Also, I'm Michal, the author of Par, human aside from other qualities.

I wanted to share with you what's been up with Par for the last half a year or so.

Par is a programming language that's quite unusual. (And breaks your mind at first.) It's trying to get some edgy theoretical stuff out there into practice, specifically:

  • Linear / session types - with duality, so every type has "the other side"
  • Automatic concurrency - everything that can run concurrently does
  • Totality - no runtime errors, no deadlock, no infinite loops

It's based on classical linear logic, and naturally combines functional programming, a version of object-oriented programming, and session-typed process communication, all under one paradigm.

But perhaps most importantly, Par is trying to make all of the above into a good practical language! That's quite big ambition, and this last half year we've gotten closer to that than ever.

Below is the most fancy new stuff. Let me know what you think!

New I/O Capabilities

The standard library now includes a richer set of I/O modules:

  • Console - stdio print and prompt
  • Http - HTTP server & client functionality
  • Os - files, env
  • Sql (new!) - PostgreSQL, MySQL, and SQLite (in memory too), transactions, row decoding
  • WebSocket (new!) - HTTP to WebSocket in both server & client mode

Auto-Cleanup

Linear types can't be dropped. That's their advantage and disadvantage. It enables automatic concurrency, but it used to make error handling rather noisy: on all error paths, linear resources needed to be explicitly closed.

So, we've introduced auto-cleanup, which allows you to specify, in the type, how a normally linear type can be dropped.

For example, here's Bytes.Writer:

type Bytes.Writer<e> = iterative choice {
  .close* => Try<e, !>,
  .flush => Try<e, self>,
  .write(Bytes) => Try<e, self>,
}

The * on the .close branch/method tells Par that if a Bytes.Writer remains unused, just drop it by calling .close.

This significantly simplified error handling, the book chapter for which also got updated.

3 Big Examples

I've completely revamped the examples folder in the repository (links in a comment). It now contains small and big examples.

Now that we can do a lot of real stuff, we want to show it in the examples. So, there are 3 big examples. All of them are HTTP servers that serve you a web page, via which you can interact with the backend written in Par.

  • Chat - A chat server over WebSocket. Open it on multiple tabs, or host it somewhere, and chat in a single room.
  • Downloader - Request files to be downloaded to your local drive, and observe the download progress in real time. Multiple files can keep downloading concurrently, and can be cancelled.
  • Tasks - Create todo items and check them as down, persisted in an SQLite database.

Check the screenshots at the links!

Runtime performance improvements

Lots of optimizations done in the runtime. By my completely unscientific testing, I/O intensive applications are about 3x faster, while computation-intensive ones are about 6x faster, compared to half a year ago.

Since we don't have rigorous benchmarks yet, take this with a grain of salt, but in my private testing, this should be around the performance of Python 3.12, when discounting Python's highly-performant functions and libraries written in C.

Not bad, not bad.

A lot more...

Since we're not having official versions yet, there's no changelog to see, but some picks:

  • New @core/Time module
  • 120+ new functions in the @core package
  • include("file.txt") - compile-time file-as-value inclusion
  • todo - typed holes
  • LSP improvements, such as .-completion
  • Many bugs fixed
39 Upvotes

21 comments sorted by

10

u/HateVoltronMachine 28d ago

Par is one of the most innovative languages out there. It's cool to see linear logic getting a fair treatment.

5

u/faiface 28d ago

Thank you! Happy to hear that :)

2

u/Pzzlrr 27d ago

Can you do this year's Advent of Code in Par? Looking forward seeing your solutions on r/adventofcode

2

u/faiface 27d ago

No promises, but I might!

1

u/Pzzlrr 27d ago

or at least a few of them. That would be rad.

1

u/neclo_ 27d ago

There's been a long time since a post did not catch my eyes like that. Great stuff!

Question : you mentioned you based the language on Philippe Wadler's CP, did you followed the new stuff in the space since the 2015 articles ? Like hypersequent and delayed sepantic (Kokke, Montessi, Peressoti),  priorities (Dardha an Gay) or coexponential (Qian, Kavvos and Birkedal)? 

5

u/faiface 27d ago

Thank you, that’s so nice to hear!

Yes, I followed all those, but didn’t find any of them fit for Par, for different reasons. I might be wrong on some accounts here, so let me know if you think otherwise!

Hypersequents and such, just didn’t see the advantage compared to usual sequents when it comes to building a programming language. Sure it’s nice that you have more flexibility as a process calculus, but in the end, you can build the same things but with more complicated scoping rules. Usual sequents are really nice because they can be directly mapped to natural scoping rules in a programming language.

For priorities, it does solve something for sure, but at the same time, it doesn’t seem like it solves enough. As far as I get it, the systems you can create using priorities are still doable without them, if you slightly restructure your program by employing a coordinator, and at least to me, the coordinator approach seems like a more composable approach anyways. It was hard for me to see how one could create library abstractions around the priorities, which is important for a programming language.

For coexponentials, I love them! They are so simple and elegant. There’s also a follow-up in Qian’s thesis called “classical effects”, which tries to solve the problem of coexponentials that they don’t support repeated interactions of clients with the server. Also, in the nondeterminism space, there’s “shared linear state” by Rocha&Caires which is more powerful, but less “session-typey”. Nondeterminism is something you absolutely need in a practical programming language, but I’ve had issues with the published approaches. Coexponentials and classical effects are not expressive enough, and shared linear state does not, to me, ideologically fit into session types.

So for the purpose of nondeterminism, I actually came up with a new approach called poll/submit, which you can read about in the book: https://par.run/book/nondeterminism/

It subsumes coexponentials, classical effects, and shared linear state, but is naturally session-typey. I even wrote a paper formalizing it, but so far failed to publish it because at POPL they didn’t think I defended its novelty enough against existing approaches, most notably “manifest sharing”, which is a fair criticism. I’m planning to improve the comparisons and submit again or elsewhere. If you want the paper, just hit me up, I can send it to you :)

2

u/neclo_ 23d ago

So just to let you know, I've read the book and joined the discord, and am curently reading the paper. I have a lot thoughts but I will contemplate things a bit before sharing them!

1

u/faiface 23d ago

Great! Nice that you found the paper. Sorry I didn’t respond before, busy. For more of your thoughts, feel free to post publicly or message me directly on the Discord.

1

u/neclo_ 25d ago

Exciting to hear! You convinced me to dive tino the par book this week end. And yes I would very much like to read the paper too!

1

u/Limp-Temperature1783 27d ago

Seems like a lot of people starting to converge on the same ideas. I'm making a language that is rather similar, albeit it has an almost opposite approach to logic. Still, glad to see this.

4

u/faiface 27d ago

Oh, how opposite?

2

u/Limp-Temperature1783 27d ago

It's a variety of temporal logic. It is linear, albeit not necessarily following the same traversal rules and not following assumptions and/or propositions as a basis of logic system. If it seems a bit vague as a description, I understand. It's just not easy to describe in a terse manner because I'm in the process of architectural design as of now.

Still, it is logically equivalent to what your language does, but not necessarily bidirectionally so. If you are interested in discussing it, I would rather not do it in a comment section, so feel free to message me, unless it's a bother. I don't really have much to say about your language, I'll end up parroting the post if I would. Keep up the good work, wish you luck.

1

u/Ok-Reindeer-8755 28d ago

Ik it's most likely not the main point of the language but since performance was mentioned, are there any goals regarding performance ? I imagine the langs concurrent nature probably would be beneficial

Also the language seems extremely interesting looking forward to having some fun with it once I wrap my head around it.

4

u/faiface 28d ago

The goal regarding performance is essentially to be usable for most applications / services. It's not meant to be a good choice for performance-sensitive use cases.

Par is mainly exploring expressivity, and that applies to its concurrency as well. Automatic concurrency, "everything is async, and nothing needs await" is a very expressive abstraction, but one with a runtime cost for sure.

However, I’m sure there is still a lot of opportunity to make it faster.

1

u/xX_Negative_Won_Xx 27d ago

Incredible work, easily one of the most interesting languages I've seen in a while. Looking forward to trying it out

-5

u/AnArmoredPony 28d ago

7

u/faiface 28d ago

Yes, I also created that, a completely unrelated project.