You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user_docs/support/faq-kcl.md
+14-3Lines changed: 14 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2513,18 +2513,29 @@ s: Hello world
2513
2513
raw_s: Hello ${worldString}
2514
2514
```
2515
2515
2516
-
## 59. How does KCL infer return types in lambdas?
2516
+
## 59. How does KCL infer types in lambdas or how to specify the type for function variables?
2517
2517
2518
-
For lambda(s),KCL automatically infers the return value type in the function body, although we can explicitly specify it. An example KCL code over here is:
2518
+
For lambda(s),KCL automatically infers the parameter types and return value type in the function body, although we can explicitly specify it. An example KCL code over here is:
2519
2519
2520
2520
```python
2521
+
schema Type1:
2522
+
foo?: int
2523
+
2524
+
schema Type2:
2525
+
bar?: int
2526
+
2521
2527
f1 = lambda t: Type1 {
2522
2528
Type2 {}
2523
2529
} # The type of f1 is (Type1) -> Type2
2524
-
2525
2530
f2 = lambda t: Type1 -> Type2 {
2526
2531
Type2 {}
2527
2532
} # The type of f2 is (Type1) -> Type2
2533
+
f3: (Type1) -> Type2 = lambda t: Type1 -> Type2 {
2534
+
Type2 {}
2535
+
} # The type of f2 is (Type1) -> Type2
2536
+
f4: (Type1) -> Type2 = lambda t {
2537
+
Type2 {}
2538
+
} # The type of f2 is (Type1) -> Type2
2528
2539
```
2529
2540
2530
2541
## 60. How to convert a list of lists to a single list in KCL?
Copy file name to clipboardExpand all lines: versioned_docs/version-0.8/user_docs/support/faq-kcl.md
+14-3Lines changed: 14 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2513,18 +2513,29 @@ s: Hello world
2513
2513
raw_s: Hello ${worldString}
2514
2514
```
2515
2515
2516
-
## 59. How does KCL infer return types in lambdas?
2516
+
## 59. How does KCL infer types in lambdas or how to specify the type for function variables?
2517
2517
2518
-
For lambda(s),KCL automatically infers the return value type in the function body, although we can explicitly specify it. An example KCL code over here is:
2518
+
For lambda(s),KCL automatically infers the return value type in the function body, although we can explicitly specify it. An example KCL code over here is:
2519
2519
2520
2520
```python
2521
+
schema Type1:
2522
+
foo?: int
2523
+
2524
+
schema Type2:
2525
+
bar?: int
2526
+
2521
2527
f1 = lambda t: Type1 {
2522
2528
Type2 {}
2523
2529
} # The type of f1 is (Type1) -> Type2
2524
-
2525
2530
f2 = lambda t: Type1 -> Type2 {
2526
2531
Type2 {}
2527
2532
} # The type of f2 is (Type1) -> Type2
2533
+
f3: (Type1) -> Type2 = lambda t: Type1 -> Type2 {
2534
+
Type2 {}
2535
+
} # The type of f2 is (Type1) -> Type2
2536
+
f4: (Type1) -> Type2 = lambda t {
2537
+
Type2 {}
2538
+
} # The type of f2 is (Type1) -> Type2
2528
2539
```
2529
2540
2530
2541
## 60. How to convert a list of lists to a single list in KCL?
0 commit comments