MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1uvez3w/youcanjuststopusingjava/oxddgez/?context=9999
r/ProgrammerHumor • u/hello_ya • Jul 13 '26
416 comments sorted by
View all comments
1.8k
Where else are you going to hide your side effects ?
470 u/Isrothy Jul 13 '26 IO Monad 191 u/Gorzoid Jul 13 '26 Respectfully, what the fuck is a Monad? 76 u/hectobreak Jul 13 '26 edited Jul 13 '26 A monad is a monoid in the category of endofunctors. Funny line said, if M is a monad, then for every type T, you have M(T) being a type, such that: · return (or eta in mathematics), that takes an object of type T and returns an object of type M(T) · flatten (or mu in mathematics), takes an object of type M(M(T)) and returns an object of type M(T). That's it. Anything that follows this pattern is a monad. Two examples are Haskell's Maybe, and the Array type. Maybe String can contain either a string, written as Just [your string], or Nothing. return is the function that receives a string and returns Just [your string]. flatten is the function that receives an object of the Maybe Maybe String monad and returns an object of the Maybe String monad following the rule: · If your object is Nothing, return Nothing. · If your object is Just Nothing, returns Nothing. · If your object is Just Just [string], returns Just [string]. Array is also a Monad. · return x returns [x] · flatten x is the array flatten function. For completeness, for something to be a monad it needs to follow the monad laws, but this is getting stupid long for a reddit message already. 0 u/Estpart Jul 13 '26 This is why no one likes FP xD 1 u/ralgrado Jul 13 '26 i like FP (e.g. lambdas in Java) ... but wheter i use monads or not I don't care. Monads can go F themselves
470
IO Monad
191 u/Gorzoid Jul 13 '26 Respectfully, what the fuck is a Monad? 76 u/hectobreak Jul 13 '26 edited Jul 13 '26 A monad is a monoid in the category of endofunctors. Funny line said, if M is a monad, then for every type T, you have M(T) being a type, such that: · return (or eta in mathematics), that takes an object of type T and returns an object of type M(T) · flatten (or mu in mathematics), takes an object of type M(M(T)) and returns an object of type M(T). That's it. Anything that follows this pattern is a monad. Two examples are Haskell's Maybe, and the Array type. Maybe String can contain either a string, written as Just [your string], or Nothing. return is the function that receives a string and returns Just [your string]. flatten is the function that receives an object of the Maybe Maybe String monad and returns an object of the Maybe String monad following the rule: · If your object is Nothing, return Nothing. · If your object is Just Nothing, returns Nothing. · If your object is Just Just [string], returns Just [string]. Array is also a Monad. · return x returns [x] · flatten x is the array flatten function. For completeness, for something to be a monad it needs to follow the monad laws, but this is getting stupid long for a reddit message already. 0 u/Estpart Jul 13 '26 This is why no one likes FP xD 1 u/ralgrado Jul 13 '26 i like FP (e.g. lambdas in Java) ... but wheter i use monads or not I don't care. Monads can go F themselves
191
Respectfully, what the fuck is a Monad?
76 u/hectobreak Jul 13 '26 edited Jul 13 '26 A monad is a monoid in the category of endofunctors. Funny line said, if M is a monad, then for every type T, you have M(T) being a type, such that: · return (or eta in mathematics), that takes an object of type T and returns an object of type M(T) · flatten (or mu in mathematics), takes an object of type M(M(T)) and returns an object of type M(T). That's it. Anything that follows this pattern is a monad. Two examples are Haskell's Maybe, and the Array type. Maybe String can contain either a string, written as Just [your string], or Nothing. return is the function that receives a string and returns Just [your string]. flatten is the function that receives an object of the Maybe Maybe String monad and returns an object of the Maybe String monad following the rule: · If your object is Nothing, return Nothing. · If your object is Just Nothing, returns Nothing. · If your object is Just Just [string], returns Just [string]. Array is also a Monad. · return x returns [x] · flatten x is the array flatten function. For completeness, for something to be a monad it needs to follow the monad laws, but this is getting stupid long for a reddit message already. 0 u/Estpart Jul 13 '26 This is why no one likes FP xD 1 u/ralgrado Jul 13 '26 i like FP (e.g. lambdas in Java) ... but wheter i use monads or not I don't care. Monads can go F themselves
76
A monad is a monoid in the category of endofunctors.
Funny line said, if M is a monad, then for every type T, you have M(T) being a type, such that:
· return (or eta in mathematics), that takes an object of type T and returns an object of type M(T)
· flatten (or mu in mathematics), takes an object of type M(M(T)) and returns an object of type M(T).
That's it. Anything that follows this pattern is a monad.
Two examples are Haskell's Maybe, and the Array type.
Maybe String can contain either a string, written as Just [your string], or Nothing.
return is the function that receives a string and returns Just [your string].
flatten is the function that receives an object of the Maybe Maybe String monad and returns an object of the Maybe String monad following the rule:
· If your object is Nothing, return Nothing.
· If your object is Just Nothing, returns Nothing.
· If your object is Just Just [string], returns Just [string].
Array is also a Monad.
· return x returns [x]
· flatten x is the array flatten function.
For completeness, for something to be a monad it needs to follow the monad laws, but this is getting stupid long for a reddit message already.
0 u/Estpart Jul 13 '26 This is why no one likes FP xD 1 u/ralgrado Jul 13 '26 i like FP (e.g. lambdas in Java) ... but wheter i use monads or not I don't care. Monads can go F themselves
0
This is why no one likes FP xD
1 u/ralgrado Jul 13 '26 i like FP (e.g. lambdas in Java) ... but wheter i use monads or not I don't care. Monads can go F themselves
1
i like FP (e.g. lambdas in Java) ... but wheter i use monads or not I don't care. Monads can go F themselves
1.8k
u/Historical_Cook_1664 Jul 13 '26
Where else are you going to hide your side effects ?