MattWindsor91 / roslyn-concepts-issues

Issue-tracking repository for captainhayashi/roslyn
4 stars 0 forks source link

Concept elision in type arguments #2

Open MattWindsor91 opened 8 years ago

MattWindsor91 commented 8 years ago

One of our current proposals is to extend method (and perhaps class) type argument inference and resolution so that:

  1. If the number of type arguments is fewer than the arity of the method/class; and
  2. the number of type arguments is the arity of the method/class minus the number of concept witnesses in the set of type parameters for that method/class; then
  3. insert the missing type parameters into their correct position in the type arguments, padding the type arguments to the arity; and
  4. perform witness type inference.

    Example

instance EqInt : Eq<Int> { /* ... */ }
instance OrdBool : Ord<bool> { /* ... */ }
instance NumDouble : Num<double> { /* ... */ }

void DoThing<A, B>(A a, B b) where EqA : Eq<A> where OrdB : Ord<B> { /* ... */ }
void DoAnotherThing<A, [ConceptWitness]NumA, B>(A[] as, B[] bs) where NumA : struct, Num<A> { /* ... */ }

// ...

DoThing<int, bool>(10, true);
// becomes DoThing<int, bool, EqA, OrdB>
// which then infers to <int, bool, EqInt, OrdBool>

DoAnotherThing<double, int>({5.5, 10.6, 97.2}, {27, 53});
// becomes DoAnotherThing<double, NumA, int>
// which then infers to <double, NumDouble, int>

Pros