Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your descriptions seem pretty good. Generally people speak of three monad laws, which you have as 1, 2, and 4. Your third law is slightly different, and I'll get to that later.</p> <p>For the three monad laws, I find it much easier to get an intuitive understanding of what they mean when they're re-written using Kleisli composition:</p> <pre><code>-- defined in Control.Monad (&gt;=&gt;) :: Monad m =&gt; (a -&gt; m b) -&gt; (b -&gt; m c) -&gt; a -&gt; m c mf &gt;=&gt; n = \x -&gt; mf x &gt;&gt;= n </code></pre> <p>Now the laws can be written as:</p> <pre><code>1) return &gt;=&gt; mf = mf -- left identity 2) mf &gt;=&gt; return = mf -- right identity 4) (f &gt;=&gt; g) &gt;=&gt; h = f &gt;=&gt; (g &gt;=&gt; h) -- associativity </code></pre> <p>1) Left Identity Law - returning a value doesn't change the value and doesn't do anything in the monad.</p> <p>2) Right Identity Law - returning a value doesn't change the value and doesn't do anything in the monad.</p> <p>4) Associativity - monadic composition is associative (I like KennyTM's answer for this)</p> <p>The two identity laws basically say the same thing, but they're both necessary because <code>return</code> should have identity behavior on both sides of the bind operator.</p> <p>Now for the third law. This law essentially says that both the Functor instance and your Monad instance behave the same way when lifting a function into the monad, and that neither does anything monadic. If I'm not mistaken, it's the case that when a monad obeys the other three laws and the Functor instance obeys the functor laws, then this statement will always be true.</p> <p>A lot of this comes from the <a href="http://www.haskell.org/haskellwiki/Monad_Laws" rel="noreferrer">Haskell Wiki</a>. The <a href="http://www.haskell.org/haskellwiki/Typeclassopedia" rel="noreferrer">Typeclassopedia</a> is a good reference too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload