Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well um, I think you're a bit off. A monad is an endofunctor, which in Hask (The category of Haskell types) is something with the kind <code>F :: * -&gt; *</code> with some function that knows how to inject morphisms (functions) into the subcategory of Hask with functions upon <code>F</code>s as morphisms and <code>F</code>s as objects, <code>fmap</code>. What you have there appears to be a natural transformation in Hask.</p> <p>Examples: <code>Maybe</code>, <code>Either a</code>, <code>(,) a</code>, etc..</p> <p>Now a monad also must have 2 natural transformations (<code>Functor F, Functor g =&gt; F a -&gt; G a</code> in hask).</p> <pre><code>n : Identity -&gt; M u : M^2 -&gt; M </code></pre> <p>Or in haskell code</p> <pre><code>n :: Identity a -&gt; M a -- Identity a == a u :: M (M a) -&gt; M a </code></pre> <p>which correspond to <code>return</code> and <code>join</code> respectively.</p> <p>Now we have to get to <code>&gt;&gt;=</code>. What you had as bind was actually just <code>fmap</code>, what we actually want is <code>m a -&gt; (a -&gt; m b) -&gt; m b</code>. This is easily defined as</p> <pre><code> m &gt;&gt;= f = join $ f `fmap` m </code></pre> <p>Tada! We have monads. Now for this monoid of endofunctors.</p> <p>A monoid over endofunctors would have a functors as objects and natural transformations as morphisms. The interesting thing is that the product of two endofunctors is their composition. Here's the Haskell code for our new monoid</p> <pre><code>type (f &lt;+&gt; g) a = f (g a) class Functor m =&gt; Monoid' m where midentity' :: Identity a -&gt; m a mappend' :: (m &lt;+&gt; m) a -&gt; m a </code></pre> <p>This desugars to</p> <pre><code> midentity' :: a -&gt; m a mappend' :: m (m a) -&gt; m a </code></pre> <p>Look familiar?</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