←back to thread

873 points belter | 3 comments | | HN request time: 0.55s | source
1. mikelinsi ◴[] No.42949853[source]
> Never go full monad in Java. what? why?
replies(2): >>42951059 #>>42953870 #
2. dionian ◴[] No.42951059[source]
because no matter how much java wants to be like scala, it's very painful to work with (verbose). There is no good Option type either. But I believe there are third party libraries out there that do a better job, if you really can't use scala for some reason
3. mrkeen ◴[] No.42953870[source]
From a use-case perspective, Haskell monads let you restrict where various effects happen. Some code can be allowed to do local mutation, other code can do shared-mutation suitable for (ACID-like) transactions. In Java you can do anything, everywhere (except throw checked exceptions from lambdas for some reason) so the monadic wrappers would give you about as much guarantee as a comment, and be less clear.

From a representational perspective, you need a generic of a generic to represent<M><A> and that doesn't really work. Or if you go for interfaces not type variables, you could have a Monad<A> but you don't know which one you have (List? Future? Parser? Either?). It's like representing the above as literal 'Object's, you'd be constantly casting.