legend-pure icon indicating copy to clipboard operation
legend-pure copied to clipboard

Provide a way to invoke generic functions with explicit type arguments

Open gbrgr opened this issue 3 years ago • 0 comments

Feature Request

Description of Problem:

Suppose I want to define a type that models a bijective Map like so:

Class BiMap<K, V> {
  to: Map<K, V>[1];
  from: Map<V, K>[1];
}

Now I want to provide to users a convenient constructor method that just yields an empty instance of BiMap:

function empty<K, V>(): BiMap<K, V>[1] {
  ^BiMap<K,V>(to=^Map<K,V>(), from=^Map<K,V>());
}

Such a function definition does not work for two reasons: First, PURE tries to find existing types named K and V. Second, there is no way to invoke the empty function by explicitly specifying type parameters at invocation (type parameters are always implicit via supplied function arguments).

gbrgr avatar Jan 20 '22 09:01 gbrgr