Caterpillar

Daily Thought - 2024-09-07

< back to list

The comptime feature in Zig is pretty interesting! It allows you to do some neat things. Here's an example from Zig's documentation:

fn max(comptime T: type, a: T, b: T) T {
    return if (a > b) a else b;
}

It's a generic max function that works with any type that provides an > operator. It's pretty similar to how generics work in Rust, but the type parameter is more similar to a normal function parameter. There are more interesting things you can do with comptime in Zig, but I wanted to show you this example, as it gave me an idea.

I'm wondering, can Caterpillar go a step further and make type parameters even less of a special thing? Like, make them completely normal function parameters, no special syntax or keyword required? And on top of that, maybe create a more natural separation between compile-time and runtime parameters?

I think the answers to all those questions might be "yes". I have an idea, and I'd like to tell you about it tomorrow.

<< previous thoughtnext thought >>