Re:Idiomatic Monads in Rust
by tempodox on Thursday April 04, 2019 @12:24PM
(#19574153)
If taking monads to Rust takes such convoluted code, my conclusion would be that it probably isn't a good fit. Compared to this, Haskell is a breeze.
[ Parent
| on HN ]
One of the purposes of publishing such papers, as see it, is triggering responses with simpler, easier proposals. They may cover the important 90% of the original, doing away with the most complexity-inducing 10%.
Implementing monads will be convoluted, using them is relatively easy. It wouldn’t change any of the existing code, but it would allow you to write a function like this:
fn double_inner<M: Monad<u64>>(m: M) -> M { m.bind(|x| M::unit(x * 2)) }
Which takes anything wrapping an integer and doubles it, whether it’s an option or result or iterator.
not sure if this is the best example – `Functor` would be enough here