Declaring generic function types

Hi again,

I am playing with the language and I wanted to see what would print $type(...) with a generic function with type parameters:

function doesNothing<T>(value:T):T {
  return value;
}

$type(doesNothing); // (value : Unknown<0>) -> Unknown<0>

It prints Unknown<0> which is a monomorph as described here:

In the example above, the first $type prints Unknown<0>. This is a monomorph, a type that is not yet known.

This is fine but I realized that we can declare Function Types but not with type parameters. This would be handy:

var fn: <T>(value:T) -> T;

I also discovered that we can’t declare a local function with type parameters as explained in this nice compiler error:

var fn = function doesNothing<T>(value:T):T {
  return value;
}
11 |   var fn = function doesNothing<T>(value:T):T {
12 |    return value;
13 |   }
   |
   | Type parameters are not supported for rvalue functions

There must be a technical reason behind that, can someone give more insight on this?

Actually this doesn’t stop us from writing this example (since Unknown<0> seems to unifiy with the type parameter apply.T):

function doesNothing<T>(value:T):T {
  return value;
}

function apply<T>(fn: T -> T, value:T):T {
  return fn(value);
}

function main() {
  var result = apply(doesNothing, 567);
  trace(result); // 567
}