Draco-lang / Language-suggestions

Collecting ideas for a new .NET language that could replace C#
75 stars 5 forks source link

Make calling a method with an Union Type dispatch to the correct overload. #129

Open Kuinox opened 10 months ago

Kuinox commented 10 months ago

This is basically a syntaxic sugar to dispatch an union type to the correct overload if the method overloads cover all the union types. This would make the following possible:

public ToJSON(a: Foo): string {}
public ToJSON(a: Bar): string {}
public ToJSON(a: int): string {}

public string Process(arg: Foo|Bar|int)
{
  ToJson(arg);
}