知识卡片
相邻类型约束函数组合
函数组合将前一步输出交给下一步。例如 f: A -> B 和 g: B -> C 组成 move |x| g(f(x)),产生从 A 到 C 的闭包。Rust 的泛型约束把共同的 B 写在两个签名里。用宏接受任意长度的语法序列后,生成嵌套的二元组合调用,每一对仍由编译器检查类型。
相关卡片 [[宏递归按语法终止]]、[[柯里化显式传入参数]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 类型化的函数组合
原书出处 · 1 处
- Declarative macros 类型化的函数组合 · 查看原书依据
But how do we write this compose? We will start simply with two input functions. No macros are required to make this work—just a lot of generics. compose_two (see the code in listing 2.16) requires two functions as parameters, both of which take a single parameter and return a result.
参考来源
- 位置:《Write Powerful Rust Macros》第02章《Declarative macros》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-2.xhtml#p128)
- 结论依据:原书由泛型 compose_two 推导到多项参数的宏递归。
- 原始内容:But how do we write this compose? We will start simply with two input functions. No macros are required to make this work—just a lot of generics. compose_two (see the code in listing 2.16) requires two functions as parameters, both of which take a single parameter and return a result.