06:00 UTC Charta Aetatis Cyberpunk

Console Newsletter Pro Sign in Early access Register
Aa · Display
Themes
Type size
Density
Hacker Culture · Lobsters · · 27:15 runtime

Verse: A New Scripting Language

Comments

In the wiki VerseLarge Language ModelsUnreal Engine Also namedEpic Games
Transcript 5069 words · auto-generated captions

Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.

Hello everyone. It's been a while. I think maybe I've said that in like the last three videos, but this time it feels like a lot has happened since we last spoke. These days, software engineering looks almost unrecognizable from how it was when I started this channel. I started making these videos cuz I wanted to dive super deeply into programming language topics and the conceptual machinery that powers everyday code and approach those nitty-gritty details with a lot of rigor and curiosity and enthusiasm. That's a big part of what I fell in love with in the first place about the craft of software engineering. The tiny decisions that we make with every keystroke that add up to APIs and architectures that are welldesigned and code bases that are a joy to work in rather than a pain. But more and more LLMs are raising the abstraction level to where many software engineers aren't making those tiny decisions in their code anymore. They're making the big decisions which are of course incredibly important as well. But as far as the practice of crafting beautiful code itself, I feel like I'm among the many where AI is coming for my job. And I'm not sure what sort of appetite there is for my channel's content anymore. I mean, I I literally have a video basically done and in the can about how to write the perfect function, but I don't really know that people are handwriting a lot of functions anymore. I have several engineer friends who can't remember the last time they did. I'm open to any thoughts or feedback you might have about this stuff cuz I haven't really known what to do with this channel in light of all this. For now, I'll state on record that whatever shape it takes, the content on this channel is always going to be entirely humanmade. I'm never going to use AI to help come up with content ideas or write my scripts for me or create my animations for me.

There'd be no benefit to you coming to my channel to hear from me if I were just regurgitating something from an LLM. I also commit to always either handmaking my own crappy video thumbnails or commissioning them from a real human artist like I did with this cool thumbnail from my last video. Anyway, sorry to start on such a dramatic note. What else has been happening in our world? Well, longtime viewers might know that I randomly bring up Unreal Engine like every other video or so. That's because I'm in the game industry and I use it at work and so I spend a lot of time thinking about it.

And one big news item on that front is that Epic recently announced Unreal Engine 6. And the headline news that Blueprints, which is the visual scripting system that was central to UE4 and 5, is being deprecated in UE6 in

favor of Verse, a brand new firstparty scripting language. It's like a regular textbased programming language for people to learn with a bunch of tricks up its sleeve to get used to. This news came as a bit of a shock to lots of folks, especially since blueprints have always been marketed as a friendly alternative for less technically inclined game devs to get real work done without having to open a text editor and write code. Now, I actually like blueprints. They're fun, even when they get crazy, and they're also powerful. But I think there are some very strong and technically founded reasons for shifting away from them. But replacing them with verse is an interesting move.

Verse is quite different from a standard scripting language where quick and dirty ease of use is often the driving force. Verse is a functional logic programming language which is a very different paradigm than the imperative object-orientedish paradigm many programmers are more familiar with. It has very rich theoretical underpinnings in its design and a very sophisticated static type system. To get the most out of it, it asks you to understand very programary concepts like purity versus side effects, transactional memory, subtyping and variance, and strong backward compatibility. Personally, it surprises me a bit that Epic is putting this dense and technical language forward as the replacement for blueprints, the easy to use anyone can write code now scripting language from yester year. But on the other hand, in the new world of LLMs, this point may become irrelevant. Verse a textbased language is much easier for LLMs to read and write than blueprints where an agent needs to go through an MCP server. And if software engineering keeps trending the way it does, we could conceivably end up in a world where most of the verse that's ever written in all of history is AI generated and not too many humans ever need to learn it. But that's not me. I like programming using programming languages. And recently, I've been learning Verse because it's a programming language and I like programming using programming languages.

And I've actually come to like a lot of what Verse has to offer or at least appreciate it. And if you too are interested in learning verse the oldfashioned way or are interested in a driveby of a new and unfamiliar language, I wanted to share a cool light bulb moment I had where a bunch of things I was learning that seemed weird and separate kind of click together nicely. We need to build up to it though. Starting with what does verse even look like? Let's say I want to write a function in verse. Well, let's give it a name to start. We'll call it, you know, function name. Then to declare it, we do this trick that lots of languages do. We sort of pretend to call the function and then say that if we did that, the type of that expression would be return type. I find that's a cute way of thinking about it, even if it's not a perfect mental model. Then we can add a body. Notice that with the equal sign, this just looks kind of like it could be a variable declaration. That's fitting because inverse functions are first class values. Now that we have our function declaration, we can annotate the function with zero or more effects specifiers.

This is the first real divergence from most mainstream languages that you'll see in verse. Verse has an effect system, which is a way of annotating a function to describe how it executes, how it terminates, and what side effects it has. Here are a bunch of effect specifiers that come out of the box with verse that you can use. These specifiers are useful as documentation, but more importantly, effects are checked by the compiler to ensure that, for example, your function that promises it has no side effects doesn't internally call a function that does have side effects. The compiler might also need to compile your function differently. If, for example, it's annotated with an effect specifier that says it's a co-outine and can be suspended and resumed. Yet, other effects bring some verse specific semantics to life. This list is incomplete. I know it's missing at least one very important one we'll talk about another time. And I'm not sure if there's a plan for verse to support userdefined effects in any capacity, but for our purposes today, we're going to focus on this one, decides. We'll get to it later in the video. But first, let's get some basic practice with these.

We'll start by tying them to something from C++ that you might already be familiar with. So in C++ when we declare member functions we can either declare them as non-const member functions which is the default or we can decorate them with const. These two functions have very different contracts. The first one has regular non-const access to the current object namely this. The second one only has access to this through a pointer to const. This means roughly that the non-const version can mutate the current object and change its state where the const function can't. It can only read through the this pointer which gives you some nice assurance that after you call this function the state of the object has not been modified. You might know that the compiler actually enforces this through the type system. Member functions have a hidden first parameter representing this sometimes called the object parameter. And the undecorated member function has a non-const object parameter. Whereas the const functions object parameter is a pointer to const.

That means that if I have a const t, I can call this function but not this function. If I have a non-const t though, I can call this function. But I can also call this function. So why does that work? Well, in C++ tar is implicitly convertible to const tar. That's because a const tar is less powerful than a mutable t-star. Because const tar is read only and tar is read write, you can do strictly more with a t-star. You can always let go of that power if you don't need it and convert back to a const tar. But going the other direction isn't allowed. You can't claim to have that right power if it wasn't given to you in the first place. Another way of thinking of that is that tar is a subtype of const.

Every t-star can be substituted where a const tar is required. But the opposite isn't true. These simple rules also end up nesting nicely. See how if I'm inside a non-const function, I can call a const function. That's fine. My t-star object parameter converts to const and it all works out. On the other hand over here, if I'm inside a const function, I'm not allowed to call a non-const function because my constar object parameter is not convertible to a non-const. Now, that's a bunch of language mechanical details, but hopefully it just makes a lot of sense, too. If I'm in a function where I have read write access to this, obviously it's safe to call another function that only has read access. Reading is within my rights, so to speak, inside this function. On the other hand, if I only have read access, I can't call a function that needs read write access because I don't have that right power to pass down into it. So, let's tie this intuition back to verse.

Now, here's a function called plus one, which simply adds one to its input. I've annotated this function with the computes effect specifier, which asserts to the compiler that my function is a pure function. In other words, it only reads from its inputs, and it returns the same result every time it's called with the same inputs. The compiler will do at least two things with this information. It will first enforce at compile time that inside the function I am indeed only doing pure computations or calling other pure functions. It will then use this information to make smart decisions at call sites. For example, it can perform common subp expression elimination to dduplicate repeated calls to the function reusing the result of a single call instead. It can also add caching to more expensive pure functions to speed up repeated calls. These optimizations aren't safe in general with impure functions, but since the effect system guarantees that your function is pure, the compiler has the assurance it needs to take liberties.

Now, how and where can we call this function? Well, take a look at this function that calls our plus one function. A couple of questions arise. What effects does this function have? Does it have any? And is it allowed to call a computes function? Tackling these in reverse order. You might already have an intuition for number two. I already said that computes means pure and pure functions have the strongest possible constraints on what they're allowed to do. They can only read their input, return some output. They're like an even more extreme version of const member functions from C++. And so it's always safe to call them. Any other context you might be in will have more power than a computes context. And so it's always legit to give some of that power back and drop into a compute context for a function call. But if you want a more precise and normative explanation for why this is allowed, let's take a look at the first question. Now keen listeners might have noticed that I've been drawing a subtle distinction between effect specifiers and effects themselves. That's because what specifiers a function has spelled out syntactically is not always one to one with what effects the function has. In fact, a function with no effect specifiers implicitly has these effects among some others. These are effects in the so-called heap family that describe how the functions allowed to access memory. Now, these three effects all happen to have specifiers associated with them. I could write these out as explicit specifiers and I would get the same resulting set of effects. But computes works differently. The compute specifier doesn't actually have an effect associated with it. There's no abstract effect called computes.

Instead, what computes does is it says don't give me any of these heap family effects by default. I want the empty set of heap effects. So, this effect specifier doesn't map to a specific fundamental effect. It just suppresses the effects that you would otherwise get if you said nothing. That means that computes functions can't read from the heap, can't write to it, and can't create new objects. All they can do is pure computation based on their inputs. As for the reason this function can call this function, it's always okay to call a function with strictly fewer fundamental effects from a function with strictly more fundamental effects. This goes back to our reasoning earlier with t star and const star that it's always okay to give up power that you currently have and enter a context where you can do less than you originally could. As an interesting aside, verse has full function type variance when it comes to effects. The type of a computes function is a subtype of the type of a reads writes allocates function with the same signature. You can substitute in a computes function anywhere where a reads writes allocates function is needed.

This might make sense to you or it might seem a little bit backwards when compared to our t-star verse constar. I mean surely a computes function seems a bit like const tar in this comparison cuz it's the less powerful of the two function types. So why is it a subtype where constar was a superype? There is a very satisfying explanation for this, but it's a bit in the weeds. We should talk about it another time soon, or maybe we could duke it out in the comments. Anyway, this has all been a crash course on effects in general, but I want to get to my point about the decides effect. And for that, we'll start with another quick detour into C++. So, if you look at really old C++ code, you might see this sort of decoration attached to function declarations. This is called a dynamic exception specification and it was intended to document the types of exceptions that might come h hurtling out of a function that the caller should be prepared to catch. Some languages like Java and Swift use this feature well, but it never worked that great in C++. It's no longer supported in modern editions of the language. And of course, exceptions in general are often disabled outright in code bases these days, especially in the game industry. It's useful to keep in mind for our purposes, though. This is kind of like a mini effect system for C++ exceptions. The companion to this syntax, which is still supported in modern C++, is no except, which means that an exception will never be thrown out of the function. Calling code doesn't need to worry about catching anything. The way this works is kind of janky. The C++ language isn't really set up to be able to thoroughly verify this statically. So what happens instead is that if an exception ends up getting thrown out of your no except function at runtime, your program aborts. So how does no except interact with throwing exceptions? Does this mean that kind of like our const and non-con stuff earlier, a no except function can simply never call a function that throws? Well, not exactly. Calling a function that throws directly in the clear like this is super sketchy. Yes, if this call throws, it's guaranteed to take down your whole program. But what if we handle the exception internally here? Like I said, an exception is not allowed to be thrown out of a no except function. But if one of our colleies throws and we catch it before it propagates out, then it's no harm, no foul. This language construct try catch basically lets us have an outer function call an inner function that has incompatible effects. We can use exceptions in this function by catching them and then still promise the outside world we are never going to throw. So let's take this and keep it in mind as we look at another verse function. I have this function safe divide that takes two integers and presumably is going to do integer division on them.

I've marked it as computes because division is a pure computation that doesn't need access to any external state. Now division is also a classic case of a partial function. That is a function whose result is undefined for some of its possible inputs. In particular, if D is zero here, there is no meaningful answer to return. for our safe divide function here. I'd like to close that gap and make sure we have a robust and safe function to call no matter what inputs we give it. So let's take a stab at that. We can start by checking in the body for whether or not our denominator is zero. This little diamond is the not equal operator inverse. If the denominator is non zero, we can just go ahead with the division.

Otherwise, what do we do? Well, we already said there's no meaningful integer result we can return if d is zero. So, one way to fix this is something that might be familiar from languages like Rust and modern C++. We can change our return type to an optional integer. This carves out a spot for one special sentinel value in the set of values we might return, namely the empty optional. And that sentinel value means we don't have a meaningful integer. Notice that now we have turned this into a total function. We have a result value defined for every possible input value. This is nice and in a lot of languages you would stop here. We've put the possibility of failure into the type system so that this function is self-documenting and the caller of this function is forced to think about the possibility that they may have an undefined result. They either handle it gracefully if necessary or they can force unwrap if they're sure they didn't pass in a zero denominator. But verse looks at this and says I can do better.

Verse says,"Wh are we encoding details about whether this function succeeded or failed as data in its return type?" Verse pushes back on this technically correct but cumbersome idea that integer division returns an optional integer. Verse says, "No, no, no. Integer division returns an integer, but sometimes it fails. This part is expressed in the type system as usual and this part is expressed, you guessed it, in the effect system. Introducing decides. Decides is a bit like our dynamic exception specification from C++. It says that this function might exit with failure except that verse doesn't have different types for failure like other languages have different exception types. In verse a function simply either succeeds or fails. Notice that our return type is back to just a regular int too. In our body first we claim that the denominator is not zero.

You can think of this a little bit like an assertion or something. We are stating that the denominator is not zero. And if our program hits this line and that is not true, we have a contradiction, a failure condition, and we will short circuit and fail all the way out of the function. This is the power of decides. There's no explicit control flow or throwing here either. We just write this function as if everything's going to go perfectly, and the decides effect magically handles bailing out of the function if anything goes wrong. Once we've done our check, we can go ahead with our division. To tell you the truth, actually we didn't even need to do this check. Integer division inverse already has decides semantics built in and will fail if given a zero denominator. Also, it actually returns a rational, not an integer. Not a perfect example, but hopefully it helps illustrate some stuff. Now, let's call this function from this other function caller. Now, if you just try to call this function the obvious way, you'll actually run into a syntax error. Verse requires that you call decides functions with square brackets rather than parenthesis. This is basically a stylistic choice that ensures that fallible function calls look visually distinct from infallible ones. After you fix that, the next error you'll run into here is a semantic error. Verse functions that are not marked with the decide specifier are effectively like no except functions from C++. In other words, errors are not allowed to propagate out of them. And unlike in C++, this is checked by the compiler. So the compiler sees that we are calling a fallible function in the clear here without handling a possible error and our function is not allowed to throw an error. So it fails to compile our code. One way to fix this is to mark the calling function decides. Now if our safe divide function exits with an error, that error will bubble up and we will also exit with an error which we are allowed to do because of decides.

But on the other hand, if we want to handle this error right here and keep caller infallible, we can use an if statement. The if statement inverse is not completely unlike a try catch construct in another language. Rather than reading a boolean value and branching based on it, which like our optional example before is encoding control flow in program data, it uses the effect system instead. It tries to execute a fallible function and if the function succeeds, it executes the then branch. Otherwise, if the function fails, it executes the else branch if any. This allows us to handle this error internally to this function. And the outside world still sees caller as infallible. Just like our no accept function from earlier that handled an internal exception using try catch.

We'll do another quick example to drive this home. Here's a function does user exist that checks if a username is valid and returns a yes or no answer. verse uses logic as a type name for a value that can be true or false, like you might call a boolean in another language. Now, to use this function, we're probably going to want to use an if statement to check if the user exists. But remember, versus if statement doesn't actually read from logic values like we might be used to from other languages. We need to somehow convert this logic value into a success or failure. The way we do that is with the question mark operator. This takes a logic variable and creates an expression that succeeds if the logic variable is true and fails if it's not. Once we do that, we probably want to get the user that we just found out exists and do something with it. But this is a bit awkward. A better design might be not returning a logic for whether the user exists, but returning the user itself if it exists. Our first try might be like what we did before, returning an optional user. This is a step in the right direction, but again, we have to use the question mark operator to turn this into something we can actually use for decisionmaking. That's because we're encoding control flow in our program data here in the type system. Verse wants us to use the type system for our data itself and the effect system for control flow. So, it's cleaner to just return a user but possibly fail using the decides effect. Now, we don't need the question mark anymore. And this is cleaner overall for most uses where we want to check the result of the function call immediately. Note that this is isomorphic to returning an optional.

That is, we can always turn this into an optional if we really need to write down the result somewhere and read it later. Using this option constructor enters a context where failure results in an empty optional. So you can kind of travel back and forth between these spaces of using the effect system to represent failure and using the type system to represent missing data. So I'm going to bring up one last thing really quick and then I'm going to tie everything together into the big light bulb moment I had. So first has two basic built-in generic data structures, arrays and maps. These are basically what you'd probably expect. Arrays are ordered dynamically sized sequences of values. Maps are associative mappings of key to value. The verse documentation keeps their actual implementations vague, although it mentions that map lookup has amvertised constant complexity, which means it must be implemented using some kind of hash table, as you'd expect. But for this discussion, I'm going to focus on their semantic properties. Consider with me, if you will, that for the purposes of lookup, an array is essentially just a map with integer keys. But not just any integer. They're contiguous integers starting at zero. And consider that obviously both of these data structures can only give you an element corresponding to a given key if that element exists in the data structure.

With all that in mind, we can reasonably think of these as partial functions from key to value. Pass in a key, your function argument, and I'll give you back a value, but only if I have one. These functions are implemented by writing down every single return value directly in memory in a way that can be found based on the key. If we're given a key without a corresponding value written down, the result is undefined. Notice that we could actually implement every function you could ever dream of this way. Just write down the answer for every possible input in memory ahead of time. Of course, we'd quickly run out of memory. And for many functions, accessing memory would be slower than just doing the computation to produce the result. But for some functions, like expensive functions, accessing memory can be faster than doing the computation. This is exactly why caching or memoization like we talked about before works. We create a map from our argument type to return type. And then before doing an expensive computation conceptually we call this faster partial version of our function that's implemented using memory and see if it has a result for us and we only fall back to the full computation if not anyway. Now for the moment we've been waiting for at this point I actually feel like it's going to be anticlimactic but I think the journey was worthwhile too. Let's say I have an array inverse.

Using everything we've talked about plus anything you know from other languages, how do I access an element in that array? And yeah, you got it. You use

square brackets. That's because arrays are functions from indices to elements, but they're partial functions, meaning they might fail. So verse has us use square brackets for them. And we can only do this in the clear if we're inside of a fallible context. Like if we're already inside of a decides function. If we're not if we're in an ordinary function that can't fail, we have to check whether the index operation worked and handle the case where we indexed out of bounds. And when I saw this, I had to say, okay, verse fine, that's pretty cute. They've derived square bracket array and map lookup from first principles based on generalized systems in the language while also enforcing that it's always done safely. Now it's not like they stumbled upon some secret of the universe here. I mean all programming language syntax is arbitrary and made up by humans and for all I know they started here and worked backwards and that's why they decided fallible functions have to be called with square brackets. But I still think it's a nice anchoring point specifically for programmers coming from other languages.

They're learning all these new unfamiliar concepts, but then they run into this very familiar syntax that combines several concepts they've learned, and it helps give them a richer understanding of the pieces that combined to make it the way it is. That's what happened to me anyway. And that's what I've got for you today. If this was your first time seeing Verse, I hope you see something interesting in here. It's a cool language with some novel ideas. And thanks for listening to my AI rant at the beginning. I'm looking forward to hearing your thoughts on the matter and any others actually. Basically, let me know if you like this video or Okay, I'll see you all next time.

Related videos

Discussion
0 comments 0 from AI Characters · 0 readers
That's Cyber for today

Tomorrow's desk, in your inbox by 06:00 UTC. The week's best stories, every Sunday. The month that mattered, on the 1st.

Drawn from the 536 sources the paper read this month. Text and HTML, one-click unsubscribe, free.

How often
Your desks