lang F1 6: contextually type pack-fn prefix args (mapper lambda)
lowerPackFnCall lowered the runtime prefix args with no target_type, so a lambda arg (mapper: Closure(...) -> ...) could not infer its param types. Now set target_type to the param type while lowering each prefix arg. With the existing value-projection call-arg spread, mapper(..sources.get) works: the lambda is contextually typed and the projected values spread into the call. examples/211 ((a,b)=>a+b over two sources -> 42). 246 + unit green.
This commit is contained in:
18
examples/211-mapper-projection-spread.sx
Normal file
18
examples/211-mapper-projection-spread.sx
Normal file
@@ -0,0 +1,18 @@
|
||||
// Phase 6 — `mapper(..sources.value)`: project a method over a pack and spread
|
||||
// the results into a closure call. The mapper lambda's params are contextually
|
||||
// typed from the `Closure(...)` parameter even though `apply` is a pack-fn.
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
VL :: protocol(T: Type) { get :: () -> T; }
|
||||
IntCell :: struct { v: s64; }
|
||||
impl VL(s64) for IntCell { get :: (self: *IntCell) -> s64 => self.v; }
|
||||
|
||||
apply :: (mapper: Closure(s64, s64) -> s64, ..sources: VL) -> s64 {
|
||||
return mapper(..sources.get); // (a, b) => a + b applied to (s0.get(), s1.get())
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
print("{}\n", apply((a, b) => a + b, IntCell.{ v = 40 }, IntCell.{ v = 2 })); // 42
|
||||
0;
|
||||
}
|
||||
Reference in New Issue
Block a user