On Monday, 4 January 2021 at 15:03:05 UTC, jmh530 wrote:
On Monday, 4 January 2021 at 14:40:31 UTC, ag0aep6g wrote:
On 04.01.21 15:37, Ola Fosheim Grøstad wrote:
On Monday, 4 January 2021 at 14:11:28 UTC, ag0aep6g wrote:
`Bar!int` is an alias. It's indistinguishable from `Foo!int`. The code fails in the same manner when you replace "Bar!int" with "Foo!int".


Wrong. This succeeds:

  struct Foo(T) {}

   alias Bar(T) = Foo!T;

   void f(T)(Foo!T x) {}

   void main() {
     f(Bar!int());
   }

You didn't replace "Bar!int" with "Foo!int". You replaced "Bar!T" with "Foo!T". That's something else entirely.

IMO, this is a better example, even if it's a little more verbose.

struct Foo(T) {}

alias Bar(T) = Foo!T;

void f(T)(Bar!T x) {}

void main() {
    auto x = Bar!int();
    f(x);
}

Also, the typesystem clearly sees the same type with two names, so there is no new nominal type (obviously):

  struct Foo(T) {}
  alias Bar(T) = Foo!T;

  static assert(is(Bar!int==Foo!int));

We are talking unification over complete types, unification over incomplete types would be more advanced... but this isn't that. We don't start unification until we have a concrete complete type to start working with.



Reply via email to