News for hackers. Stuff that matters.
Re:Advanced Programming Languages (2009) by askonomm on Sunday March 06, 2022 @10:49AM (#30578326)
I, too, have tried to figure out what exactly are monads, and have come away even more confused than I was before.
Re:Advanced Programming Languages (2009) by exdsq on Sunday March 06, 2022 @11:53AM (#30578859)
You know how some functions return a value or an error? Imagine trying to compose several of those functions, passing the value into the next function or handling it’s error. That ends up with a lot of boilerplate. The first time I wrote a Monad was because of this issue. Wrapping this series of function calls in a Monad allows you to write something that reduces that boilerplate by handling the errors of any functions within it, so you can compose them like you’d want

How do you handle state in a language like Haskell that doesn’t have mutable state? You pass a data value between functions keeping track of everything, as an extra argument. Imagine the boilerplate of that! Every function suddenly needs an extra argument for Data, regardless of if it needs it, to keep it around. The State Monad deals with that boilerplate.

Re:Advanced Programming Languages (2009) by tester756 on Sunday March 06, 2022 @10:59AM (#30578400)
I've heard that dividing e.g 1 by 0 in Excel feels like a monad

it's either value or dividing by 0 error :)