generic_function_apply.carbon 451 B

123456789101112131415161718192021
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. package ExecutableSemanticsTest api;
  5. fn apply[T:! Type, U:! Type](f: fnty (T) -> U, x: T) -> U {
  6. return f(x);
  7. }
  8. fn positive(x: Bool) -> i32 {
  9. if (x) {
  10. return 2;
  11. } else {
  12. return -2;
  13. }
  14. }
  15. fn main() -> i32 {
  16. return apply(positive, false);
  17. }