#Remove anytype?

1 messages · Page 1 of 1 (latest)

novel mica
#

I found out that zig doesnt take language proposals on github anymore so i'm posting this here because i wonder what people think :D

Random idea: replace anytype with functions that imperatively check for type conformance?

instead of

fn foo(sink: anytype) void { ... }

it would be

fn foo(sink: isWriter) void { ... }

where

fn isWriter(comptime t: type) void {
  if (!std.meta.hasFn("write")(t)) @compileErorr(...);
}

I dont think it makes currently sense to use a function name in place of function argument?

red crane
#

i guess you could always bring it back with this lol
fn anytype(comptime T: type) void {}

#

from what i know though andrew isnt too big a fan of type checking on anytypes and just wants the duck typing system to do that for you

#

what would be nice (imo) is if in the error trace for an incorrect type on an anytype paramter, it included the user's call site (not just as a line number, but the actual call site and point to the argument that was of the wrong type)

novel mica
#

yeah the compile errors from the checking function could totally be attached to the call site argument. I think it would look really nice

#

the thing about anytype duck typing is that the error can occur outside of your code and it says something like 'x has no y' where x is some random local variable.