Note that there are some explanatory texts on larger screens.

plurals
  1. POMonad theory and Haskell
    text
    copied!<p>Most tutorials seem to give a lot of examples of monads (IO, state, list and so on) and then expect the reader to be able to abstract the overall principle and then they mention category theory. I don't tend to learn very well by trying generalise from examples and I would like to understand from a theoretical point of view why this pattern is so important.</p> <p>Judging from this thread: <a href="https://stackoverflow.com/questions/2366/can-anyone-explain-monads">Can anyone explain Monads?</a> this is a common problem, and I've tried looking at most of the tutorials suggested (except the Brian Beck videos which won't play on my linux machine):</p> <p>Does anyone know of a tutorial that starts from category theory and explains IO, state, list monads in those terms? the following is my unsuccessful attempt to do so:</p> <p>As I understand it a monad consists of a triple: an endo-functor and two natural transformations.</p> <p>The functor is usually shown with the type: (a -> b) -> (m a -> m b) I included the second bracket just to emphasise the symmetry.</p> <p>But, this is an endofunctor, so shouldn't the domain and codomain be the same like this?:</p> <p>(a -> b) -> (a -> b)</p> <p>I think the answer is that the domain and codomain both have a type of:</p> <p>(a -> b) | (m a -> m b) | (m m a -> m m b) and so on ...</p> <p>But I'm not really sure if that works or fits in with the definition of the functor given?</p> <p>When we move on to the natural transformation it gets even worse. If I understand correctly a natural transformation is a second order functor (with certain rules) that is a functor from one functor to another one. So since we have defined the functor above the general type of the natural transformations would be: ((a -> b) -> (m a -> m b)) -> ((a -> b) -> (m a -> m b))</p> <p>But the actual natural transformations we are using have type:</p> <p>a -> m a</p> <p>m a -> (a ->m b) -> m b</p> <p>Are these subsets of the general form above? and why are they natural transformations?</p> <p>Martin</p>
 

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