Hacker News new | ask | show | jobs
by ekidd 38 days ago
(Yes, I typed "comprehensions", but autocorrect is not my friend, I'm sad to say. Thanks for the correction!)

> Why the "almost"? They are all monads (I suppose you meant list comprehensions)

Sort of. In the right language, with the right implementation, any of these can be monads. In practice, JavaScript Promises aren't quite monads, and everything in Rust is a bit complicated because we have things like FnOnce vs Fn, and so on. And even when Rust has something that's conceptually a monad, you can't actually "impl Monad" for it, because the type system isn't quite expressive enough.

In general I think it's mistake to accidentally implement something that's not quite an algebraic or categorical structure. This often means that your design is just a bit "off" of a much cleaner design. But sometimes, like in Rust, you know why you can't use the clean mathematical structure.