4 ms·
Here's an extended explanation of how monad 'lift' works: You have a box (one monad). Inside the box is a jar (one monad) and inside the jar is an apple. You
by aetherspawn 10y ago
Here's an extended explanation of how monad 'lift' works:
You have a box (one monad). Inside the box is a jar (one monad) and inside the jar is an apple.
You want to write on the jar, so you give it to your friend but he's a moron and doesn't know how to open the box. The `lift` function opens the box, gives him the jar so he can write on it, then puts it back in the same box.
`lift` is for executing monad stuff within other monads when you have jars in boxes and need to juggle them around a little bit, but all your friends are idiots.
`liftM` is the same thing actually, but can be used on the apple in the jar since the apple isn't already a monad. If you need to swap the apple for another apple, but it's inside the jar inside the box, you need to use the composition of `lift` and `liftM` to first take the jar out the box, and then the apple out of the jar (but it'll pack them all up when you're done).