On Tuesday, 14 June 2016 at 12:57:01 UTC, Chris wrote:
Dynamic typing should only be allowed to the extend `auto` works:

var name = "Herbert"
// ...
name = "Brown"  // ok

name = 5 // error

this is still error-prone. why don't just do static typing instead, and introduce `anything` type, which is "variant", and can hold literally anything? with `auto` you'll barely need to think about types at all.

and yep, compiler can turn runtime typechecks in compile-time specialization — kinda like templates. so we'll have something like this:

// this does runtime type checks
auto add (auto a, auto b) { return a+b; }

// this does compile-time specialization, but
// can also be executed by very straightforward
// interpreter
auto add2 (auto a, auto b) {
  if (typeof(a) is int && typeof(b) is int) {
    // here compiler knows actual types of `a` and `b`
    return a+b;
  } else {
    throw new Error("wut?!");
  }
}

Reply via email to