-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nit: anytype is a really inconsistent name #5893
Comments
I agree, and personally like edit: not sure if I agree with myself anymore |
Important part was missed - declaration.
What's problem? |
+1 for |
Seconded. I found it terribly confusing when the ZIg formatter started changing my |
@data-man Something like so:
where I would have assumed |
+1 for |
My opinion: I suggest plain |
I hard disagree with this.
Nothing is ambiguous, the only reason you have an ambiguity here is because you are omitting the "The type of" statement and transforming the statement around a bit (which is ususally fine) but for some reason you doing it incorrectly for anytype.
Additionally there is a bit of a misunderstanding conflating values themselves to types to superclasses of types.
A variable that hold some unknown value is just a redundant way of saying "a variable".
This suggests that [the type of] Anyway for more on superclasses, I understand why all this confusion specifically happens for
Then the misinterpretation " Anyway I'm sorry if my response is long and convoluted, but please read through it again if you don't understand. I spent a long time thinking about why this was wrong but I couldn't quite put it into words. It might not be abundantly clear, but I assure you, |
@AssortedFantasy You seem to be putting a lot of weight on a specific translation of Zig syntax into English, and moreover on a specific syntactic ambiguity which this particular translation has. There are other ways of thinking, and many of them arrive at different places. Just because something makes sense to you doesn't mean it's the only or best possible way of thinking.
|
This is rather dismissive and rude. Also, from the very fact that this thread exists, evidence suggests that its intent and meaning are not as clear as you're implying. |
Easy there, I can sense the passions in this thread escalating a bit. Let's all take a moment to remind ourselves that we have each others' best interests in mind, and try to keep the arguments focused on the technical bits. One thing to remember is that the ultimate decisions here will be based on the technical points made, and nothing else. If somebody makes a bad argument, I promise you I know it is a bad argument, you can just let it slide. Please, for my sake 😅 |
@EleanorNB @timmyjose I understand I might come off as a bit aggressive, Sorry about that and I'll try to be a bit more agreeable from now on if that makes for better debate. I was trying to avoid the word "supertype" and "superclass" because its not really what I meant, it implies that it's somehow a different structure than a type itself, a higher level abstraction of sorts, but its not, it's just a union of types (which is still just a type). Let's get away from shakey language and maybe I can show my same point again with pure mathematics, then I can show why I personally believe In mathematics, when you're being formal, you need to specify the domain (and codomain) of your functions when you define them. For a function f(x,y) = ln(x)+y you'd need to specify something like x ∈ R+ and y ∈ R. I believe that Zig should try to match this. So then
Basically I don't believe
The above is correct, k actually is an element of any of those things. And it also shows why I don't like using I hope maybe this makes a bit more sense and is less angry sounding. To complete my argument from the last thing, my point about how the conflating confusion shows up is also shown in the mathematics. The very last thing at the end of the union,
Since unions of types are still types (which are themselves sets of values) then type is a powerset of anytpe. Regardless, even with this weird recursive structure a single value by itself never appears on the left hand side (though all sets containing a single value does). So you can again see.
The conflatement happens becuse [in Zig] a union of all types is not completely different from a union of all values (
One way to linguistically resolve this inconsistency is to say that This seemed reasonable until I realized that the only reason this makes sense grammatically is that it manages to avoid defining/mentioning the domain that you're talking about. It's the set of all things in some unmentioned universe of values. It's poorly defined, you might take it to be any value of a |
TLDR; I think the fact that I think the confusion here is caused by an inconsistency with the "any*" types.
This is in contrast with const std = @import("std");
fn takeAnyError(x: anyerror) void {}
fn takeAnyFrame(x: anyframe) void {}
fn takeAnyType(x: anytype) void { }
pub fn main() void {
std.debug.print("{}\n", .{&takeAnyError});
std.debug.print("{}\n", .{&takeAnyFrame});
// compile error because takeAnyType is generic
//std.debug.print("{}", .{&takeAnyType});
} At first glance, all 3 |
That is a good point. Perhaps |
I like fn a(b: vartype) void {
// @TypeOf(b) is *constant*, and will never change within a function permutation
} How about something that indicates generic type? |
That's not correct, the type can change if the variable is not comptime {
const Any = struct { value: anytype };
var a = Any{ .value = "foo" };
a.value = 4;
a.value = Any{ .value = 3.0 };
} |
I like |
I agree with what @SpexGuy said in his original comment:
|
How about |
In my experience |
How about |
I was about to suggest autotype. |
I like autotype, I think it's the best option I've heard yet.
I might prefer `auto` over `autotype`, since it doesn't imply that the
value is of type type, but that might just be me.
|
With |
C++ uses |
@SpexGuy, you keep emphasizing this point, but I'm not sure I follow. The documentation only mentions |
@zzyxyzz Afaict atm this is only used in the standard library itself in some However, it is also very useful for building up tuples. // args is `anytype`, will be apssed to a std.fmt function
// We intercept u21 unicode codepoint values and encode them as utf8
const ArgTuple = struct {
tuple: anytype = .{},
};
var arg_list = ArgTuple{};
for (args) |arg| {
if (@TypeOf(arg) == ?u21) {
if (arg) |cp| {
arg_list.tuple = arg_list.tuple ++ .{ctUtf8EncodeChar(cp)};
} else {
arg_list.tuple = arg_list.tuple ++ .{"null"};
}
} else if (@TypeOf(arg) == u21) {
arg_list.tuple = arg_list.tuple ++ .{ctUtf8EncodeChar(arg)};
} else {
arg_list.tuple = arg_list.tuple ++ .{arg};
}
} I agree with @SpexGuy here, the fact that the type of an |
The type of an
|
What if, instead of
// Parameter order
fn foo(a: @TypeOf(b), b: @TypeOf(b)) void {
}
// In-place contract validations
fn foo(a: ValidateContract(@TypeOf(a))) void {
}
fn ValidateContract(contract: type) type {
// some meta validation here
return contract;
}
// Type transformations
fn foo(a: TransformType(@TypeOf(a))) void {
}
fn TransformType(arg_type: type) type {
if (arg_type == comptime_int) {
return i64;
} else {
return arg_type;
}
} |
i like #9260 as a solution to this |
@batiati |
How about simply |
A bit more work, but why not just:
this possibility seemed to have gotten buried under a previous post that had a prefixed generic. |
Because |
In array's it means infer the length |
My brainstorm came up with: |
After getting some more Zig-experience If this cannot be solved by eliminating it and we're choosing a new name then my ordered preferences:
|
fn myFunction(x: vary, y: vary) vary {} |
Indeed, this cuts to the heart of it. It is clear that AssortedFantasy's reasoning, despite the time he spent on it, his assurances that it is correct, and the 29 upvotes it received, is in fact not correct, from the fact that we have Another way to put this is that a type designator says what a variable is and what type it has. So |
fn myFunction(x: unset, y: unset) unset {} |
Please let's not just flood this issue with drive-by keyword suggestions which just vaguely match the idea. If you have a suggestion, justify why you consider it an improvement on status quo, and why it fits with Zig's existing keywords and types. Also note that, as always, your opinion will have a lot more weight if you have demonstrable practical experience using Zig. |
I agree with you. |
To repeat my previous comment: a type designator describes the thing it's the type of, not itself. In
|
forget the anyarg one, it was a quick one and it doesn't even make so much sense so I edited it. |
If |
You can already use |
This comment was marked as off-topic.
This comment was marked as off-topic.
how would you express that in function types? |
Good point, either way |
Sorry, this is kind of nitpicking, but it's been bothering me.
The value of a variable of type
anyerror
is some error.The value of a variable of type
anyframe
is some frame.The value of a variable of type
anytype
is usually not a type.Said another way,
A variable that holds some unknown error is an
anyerror
.A variable that holds some unknown frame is an
anyframe
.A variable that holds some unknown type is a
type
.A variable that holds some unknown value is an
anytype
?var
was a bad name because it was overloaded with the mutability specifier. But aside from that, IMO it was an ok name. I don't think we should restore it but I thinkanytype
is also confusing.any
might be a good choice except that it is a common enough variable or function name that the language probably shouldn't reserve it.infer
was suggested previously, but doesn't convey that the type can change over the variable's lifetime. Maybeanyvalue
,anyval
, orvartype
would be better?The text was updated successfully, but these errors were encountered: