<p>Just read one definition:</p>
<p>A monad is just the minimal amount of structure needed to overload a function composition in a way that performs an extra computation on the intermediate value.</p>
<p>My Explanation:</p>
<p>In a single program, you will licky have many functions such as those dealing with IO and others dealing with Computation. Function composition then enables us to chain functions together (basically piping the output of one function into another).</p>
<p>This works well when the later functions expect the type of data given to them, but will fail if the data type is not what's expected. To get around this we normally refactor functions using factories or decorates in languages such as python.</p>
<p>Now in functional programming, we have an alternative way of doing this and that is the monad. It basically can be thought of as a tuple of operations attached to a data type (or container of data). This tuple of operations is a wrapping and an unwrapping function that allow polymorphic (arbitrary) data types to work with arbitrary functions.</p>
<p>TLDR:</p>
<p>basically, a  monad allows the output of one function to be compatible with another.</p>

CC BY-SA 4.0
2022-06-14T03:52:26.780Z
2022-06-14T03:52:26.780Z
KryptoKing
<p>I have done a couple of videos trying to explain monads, <a href="https://www.youtube.com/watch?v=SndXh7vZCd0&amp;list=PLckjwRWdD3JToFKE3qzVEI-VhbzVnoJui&amp;index=15&amp;t=15s" rel="nofollow noreferrer">one explaining the formal implementation</a> and <a href="https://www.youtube.com/watch?v=P2yjubqEkl4&amp;list=PLckjwRWdD3JToFKE3qzVEI-VhbzVnoJui&amp;index=16&amp;t=2s" rel="nofollow noreferrer">one implementing a new monad from scratch</a></p>
<p>the second in particular shows you how monads do allow side effects by considering the container (your <code>Monad</code> instance) as a context</p>
<p>this way the side effect is not &quot;outside&quot; the function, since the monad is part of the function</p>
<p>this explanation is very raw but in <a href="https://www.youtube.com/watch?v=P2yjubqEkl4&amp;list=PLckjwRWdD3JToFKE3qzVEI-VhbzVnoJui&amp;index=16&amp;t=2s" rel="nofollow noreferrer">the second video</a> you can see how the bind operator (<code>&gt;&gt;=</code>) handles all the &quot;side effects&quot;</p>

CC BY-SA 4.0
2022-06-14T14:22:47.887Z
2022-06-14T14:22:47.887Z
Michele Nuzzi
<p>I was asked by a friend trying to learn plutus what a monad was, so I began talking about category theory. It seems that this confused him further how would you explain monads to a noob?</p>
<p>Whats your mental model for dealing with them?</p>

CC BY-SA 4.0
2022-06-14T02:45:53.420Z
Great question!, maybe also post in the regular stackoverflow?
zhekson
CC BY-SA 4.0
2022-06-14T03:26:49.320Z
You mean the haskell one?
KryptoKing
CC BY-SA 4.0
2022-06-14T03:35:29.833Z
Don't think there is one, but stackoverflow may help...
zhekson
CC BY-SA 4.0
2022-06-14T03:42:27.600Z
okay thanks ill do that
KryptoKing
CC BY-SA 4.0
2022-06-15T02:37:16.193Z
If you have some python experience, this might be helpful: https://github.com/cffls/py2hs#monad. It implements a monad in Python, explains the motivation, and then shows how to do the same thing in Haskell.
Jerry
CC BY-SA 4.0
2022-06-15T13:31:24.930Z
Thanks, man. I don't really need help with monads but I love python and really surprised to find this existed. gonna check it out thanks a bunch.
KryptoKing
<plutus><smart-contract><haskell><script><monad>
Whats Your Mental Model For Monads?
# Whats Your Mental Model For Monads?

(Asked by: username_0 on 2022-06-14)

I was asked by a friend trying to learn plutus what a monad was, so I began talking about category theory. It seems that this confused him further how would you explain monads to a noob?

Whats your mental model for dealing with them?

**Tags:** plutus, smart-contract, haskell, script, monad
> **Comments:**
> **username_1**: Great question!, maybe also post in the regular stackoverflow?  
> **username_0**: You mean the haskell one?  
> **username_1**: Don't think there is one, but stackoverflow may help...  
> **username_0**: okay thanks ill do that  
> **username_2**: If you have some python experience, this might be helpful: https://github.com/cffls/py2hs#monad. It implements a monad in Python, explains the motivation, and then shows how to do the same thing in Haskell.  
> **username_0**: Thanks, man. I don't really need help with monads but I love python and really surprised to find this existed. gonna check it out thanks a bunch.  

---

## 2 answers

### Answer by username_0 on 2022-06-14. Score: 2 | Accepted answer

Just read one definition:

A monad is just the minimal amount of structure needed to overload a function composition in a way that performs an extra computation on the intermediate value.

My Explanation:

In a single program, you will licky have many functions such as those dealing with IO and others dealing with Computation. Function composition then enables us to chain functions together (basically piping the output of one function into another).

This works well when the later functions expect the type of data given to them, but will fail if the data type is not what's expected. To get around this we normally refactor functions using factories or decorates in languages such as python.

Now in functional programming, we have an alternative way of doing this and that is the monad. It basically can be thought of as a tuple of operations attached to a data type (or container of data). This tuple of operations is a wrapping and an unwrapping function that allow polymorphic (arbitrary) data types to work with arbitrary functions.

TLDR:

basically, a monad allows the output of one function to be compatible with another.


---

### Answer by username_3 on 2022-06-14. Score: 0

I have done a couple of videos trying to explain monads, [one explaining the formal implementation](https://www.youtube.com/watch?v=SndXh7vZCd0&list=PLckjwRWdD3JToFKE3qzVEI-VhbzVnoJui&index=15&t=15s) and [one implementing a new monad from scratch](https://www.youtube.com/watch?v=P2yjubqEkl4&list=PLckjwRWdD3JToFKE3qzVEI-VhbzVnoJui&index=16&t=2s)

the second in particular shows you how monads do allow side effects by considering the container (your `Monad` instance) as a context

this way the side effect is not "outside" the function, since the monad is part of the function

this explanation is very raw but in [the second video](https://www.youtube.com/watch?v=P2yjubqEkl4&list=PLckjwRWdD3JToFKE3qzVEI-VhbzVnoJui&index=16&t=2s) you can see how the bind operator (`>>=`) handles all the "side effects"


---

