|
|
|
|
|
by gemstones
1161 days ago
|
|
I think the commenter who mentioned syntax is on to something. If I write this fn my_big_subroutine(ma: Option<isize>, mb: Option<isize>) -> Option<bool> {
match (ma, mb) {
(Some(a), Some(b)) => Some(a > b),
(_, _) => None,
}
}
it’s clearer to me what the intent is. I’m not sure why the other syntax is so hard for me but it feels hard to understand for some reason. |
|
> it’s clearer to me what the intent is. I’m not sure why the other syntax is so hard for me but it feels hard to understand for some reason.
We can write `myBigSubroutine` with case matching:
In fact, the `do` notation version desugars to something equivalent to this snippet.The motivation for using the `Monad` instance (and thus `do` notation), is that it allows us to be polymorphic over the effect described by `>>=` (and thus `do`).
This lets us have a customized version of sequencing computations specialized to whatever "effect" we need, not just casing on optional values.