4 ms·
Your explanation makes sense, but I don't see how are Monads different from Rust's Option Type (or Java's Optional Type?), or any other nullable type?
by nemothekid 11y ago
Your explanation makes sense, but I don't see how are Monads different from Rust's Option Type (or Java's Optional Type?), or any other nullable type?
- eutectic 11y agoThe maybe monad is just being used as an example here, but Haskell allows you to implement the same interface for any applicable type. for example; IO, mutable state, parsers, etc.
- andrewaylett 11y agoOption and Optional are indeed monads, and Java's Optional.flatMap() function is the monadic /bind/ function. But not all monads are Optional -- List is also a monad, and they go on to get a lot more complex than that. I found that reading about Haskell really helpful for my Java development, and that looking at really simple monads like Optional, and using them in my code, was really helpful for understanding how more complicated monads work. Jumping straight into Haskell's IO monad is really unhelpful.
- tel 11y ago"Monad" is more like an adjective. "Option" is a monad, but, interestingly, the union type (A | null) is not.
- dllthomas 11y agoAs I understand it, this is because nullability (typically?) doesn't nest and so can't be a functor (with the whole of the types of the language as domain). If you can't wind up with m (m a), then there is no place for join.
- tel 11y agoYeah, exactly. The other way to see it is to note that `Nothing(null)` is a perfectly reasonable Javascript expression which ought to mean something different from `null` alone. If that cannot be true then you don't actually have parametricity.