logoalt Hacker News

brabel08/10/20251 replyview on HN

The Zig code returns any `type`, it's impossible to say what that is without looking at the implementation. It can be different types completely depending on the comptime arguments.

But I agree it probably returns a struct type.

Assuming that's the case, you're right and the equivalent would be:

Zig:

    fn ArrayListType(comptime T: type) type {
D:

    ArrayList!T ArrayListType(T)() {
But now the D version is more specific about what it returns, so it's still not exactly equivalent.

Replies

dpassens08/10/2025

No, you misunderstand. The function doesn't return any type, it returns _a_ type. Types are values in Zig and returning them from function is how generics are implemented.

show 1 reply