basic/match-pattern/option #693
Replies: 15 comments 25 replies
-
此处的 |
Beta Was this translation helpful? Give feedback.
-
i am a looser |
Beta Was this translation helpful? Give feedback.
-
Some(5)与match 模式中分支 Some(i)匹配,i被解构成5. |
Beta Was this translation helpful? Give feedback.
-
从ADT(algebraic data type)角度理解,要比从null角度理解更好。 |
Beta Was this translation helpful? Give feedback.
-
I am a looser |
Beta Was this translation helpful? Give feedback.
-
是不是等同于 |
Beta Was this translation helpful? Give feedback.
-
飘了,没看到习题 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I am tighter |
Beta Was this translation helpful? Give feedback.
-
Option其实是Maybe类型(函数式编程中的可有可无的类型)。 Some(3).map(|x|x+1).map(|x|x*2); 你可以安全的对一个 |
Beta Was this translation helpful? Give feedback.
-
新手很难理解 几点: |
Beta Was this translation helpful? Give feedback.
-
java里面的optional? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
感觉不如kotlin的 T? 优雅 |
Beta Was this translation helpful? Give feedback.
-
这个事实能够保证的前提是一个关键词或者某种实现手段让你的类型是 “要么 1, 要么2, ……”,也就是 rust 里的 enum,在类型论中是 Sum Type (OR 的韵味)。btw,struct 本身是 Product Type,同构于一个 fixed finite length tuple,因此可以使用 projection map (point.1) 或者命名式的 point.x 来调取一个属性。 回到话题,任何使用归纳类型定义的代数数据类型其 pattern matching 的实现和理解在我看来必须达到简单的类型论层次,或者你需要理解你在做的事情是一个 OR。其余类比三目运算符的都是偷懒耍滑。 甚者,如果你熟悉 FP 下的数据结构,纯粹使用构造器上的 pattern matching 和离散数学的归纳法证明会有很相似的地方,这也是达到 coding 和 math 同构的一个重要理解。 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
basic/match-pattern/option
https://course.rs/basic/match-pattern/option.html
Beta Was this translation helpful? Give feedback.
All reactions