5 ms·
"No, you don't have to learn monads." Ha! This is ironic because a present discussion over some syntactic sugar (maybe more) to make Rust error handling feel m
by eximius 11y ago
"No, you don't have to learn monads."
Ha! This is ironic because a present discussion over some syntactic sugar (maybe more) to make Rust error handling feel more part of the language and more ergonamic may be ad-hoc monads. Not that the programmer needs to know that - it's just something that should happen to play nice in the rest of the Rust type ecosystem
- M2Ys4U 11y agoI was under the impression that `Option<T>` and `Result<T, E>` were monads.
- mafribe 11y agoMONSIEUR JOURDAIN: Oh, really? So when I say: "x := x+1" and "throw new Exception” is that monadic? PHILOSOPHY MASTER: Most clearly. MONSIEUR JOURDAIN: Well, what do you know about that! These forty years now I’ve been using monads in programming without knowing it! ------------------------------- With many apologies to Molière, many things are monadic including state and exceptions. Most programming languages introduce them as first-class core concepts rather than as monad instances. Hence you can use them innocently, without realising that they are monadic.
- u320 11y agoYes but the Rust type system cannot express monads, so they aren't monads in the type sense (they don't implement a specific Monad trait).
- steveklabnik 11y agoFun Trivia Fact: Rust's type system was[1] Turing complete. So you could actually have monads. You just wouldn't want to. 1: The program that proved this no longer compiles, so we're not sure if the type system is or is not at the moment.
- eximius 11y agoI would love to see this program. Maybe even spend some time trying to get it to compile.
- steveklabnik 11y agohttps://www.reddit.com/r/rust/comments/2o6yp8/brainfck_in_rusts_type_system_aka_type_system_is/cmkrjz2 https://www.reddit.com/r/rust/comments/2o6yp8/brainfck_in_ru... was one of them
- Manishearth 11y agoI think this is still possible with associated types. You can imitate higher kinded types with associated types, just that you wouldn't want to. I recall someone posting a Monad or Collection HKT example when associated types were proposed.
- saurik 11y agoWhat makes monads in Haskell interesting is that someone identified them as a pattern, generalized their usage, and then syntax was added to the language that lets you compose them in a natural manner. Sequential execution itself "is a monad", but in most languages we express that using something as simple as ";" or "\n": Haskell effectively generalized the idea of statements to support anything that is monadic, which is why identifying something as a monad ends up becoming so interesting in Haskell as opposed to many other languages.
- pcwalton 11y agoAnd Haskell gave up rich control flow (break, continue, early return) by doing so. If you trace through what having those statements means for monads as a first-class concept, you find that the situation becomes very much not that simple.
- ngrilly 11y agoI've never heard this argument before. Very interesting.