this post was submitted on 10 Sep 2023
51 points (89.2% liked)
Programming
17333 readers
340 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Haskell, because nobody knows haskell
Unfortunately, no one can be told what a monad is. You have to see it for yourself (then you won’t be able to explain it to anyone)
If you use JavaScript, you've probably seen a monad, since Promise is a monad. Unit is
Promise.resolve()
, bind isPromise.then()
. As required,Promise.resolve(x).then(y) === y(x)
(unit forms a left identity of bind),y.then(Promise.resolve) === y
(unit forms a right identity of bind), andx.then(y.then(z)) === x.then(y).then(z)
(bind is essentially associative).You even have the equivalent of Haskell's fancy do-notation (a form of syntactic sugar to save writing unit and bind all over the place) in the form of async/await. It's just not generalized the way it is in Haskell.