Main1.hx 571 B

1234567891011121314151617181920
  1. enum ToString<T> {
  2. ToString<S>(s:S, f:S->String);
  3. }
  4. class Main1 {
  5. static function main () {
  6. var d1 = ToString(5, function (i:Int) return "" + i);
  7. var d2 = ToString("bar", function (i:String) return i);
  8. toString(d1);
  9. toString(d2);
  10. }
  11. public static function toString<T>(x:ToString<T>) {
  12. switch (x) {
  13. case ToString(a,f):
  14. // at this point, we don't know the type of a and the parameter type of f, but we know that they are the same type and cannot be used with other types.
  15. trace(f([1,2])); // shouldn't work here
  16. }
  17. }
  18. }