Baudin999 / ZDragon_Old_002

ZDragon is moving to .NET!
MIT License
1 stars 3 forks source link

Generics - Simple #18

Closed Baudin999 closed 4 years ago

Baudin999 commented 4 years ago

Add simple generics to the resolver and the type checker:

Example:

type Request 'a =
      Header: RequestHeader;
      Body: 'a;

alias CustomerRequest = Request Customer;

The last line, the alias resolves the Request with type Customer and returns a new type called CustomerRequest.

Baudin999 commented 4 years ago

Currently we've implemented the following:

type Foo 'a =
    Base: 'a;

alias ConcreteFoo = Foo String;

Results in two types, the alias is removed from the resulting AST because it could completely be resolved.

type Foo 'a 'b =
    Base1: 'a;
    Base2: 'b;
    Base3: 'a;

alias ConcreteFoo = Foo String Number;

Again, results into two types, all field types will be resolved in the order of the resolution parameters.

result:

type ConcreteFoo =
    Base1: String;
    Base2: Number;
    Base3: String;

NOTE: We do not allow partial resolution. So the following scenario is not allowed!

type Foo 'a 'b =
    Base1: 'a;
    Base2: 'b;

alias ConcreteFoo 'a = Foo String 'a;