
Monads Made Difficult - rwosync
http://www.stephendiehl.com/posts/monads.html
======
tome
Haskell's Monad is a very, very special case of the mathematical monad. The
problem with Stephen Diehl's approach is that it treats the topic in full
generality making it much harder to understand how the special case is
actually much simpler.

I prefer
[http://web.jaguarpaw.co.uk/~tom/blog/posts/2012-09-02-what-i...](http://web.jaguarpaw.co.uk/~tom/blog/posts/2012-09-02-what-
is-a-monad-really.html), but that's probably because I wrote it.

~~~
effn
I think this is for people that already know how to use monads effectively in
Haskell and wants to learn more about the mathematical background.

~~~
freyrs3
This is explicitly not a writeup for beginners ( ergo the title ), it's a
side-by-side description of the /very/ general categorical description and how
you can model that in Haskell. The three parameter form of morphism
composition ( i.e. c y z -> c x y -> c x z ) would be quite unwieldy in day-
to-day programming but it does illustrate the underlying definitions better to
have categories explicit.

~~~
trobertson
I don't mean to nitpick, but the three parameter form is exactly what you use
in day-to-day Haskell programming. You simply let c be the infix (->), and you
get (y -> z) -> (x -> y) -> (x -> z). We just tend to think of it as a two
parameter form because a lot of the time, you can think of (->) as syntax, as
opposed to the type that it is.

~~~
lelf
Yup. This is straight cut from Control.Category module:

    
    
      instance Category (->) where
          id = Prelude.id
          (.) = (Prelude..)

------
jfarmer
Yes. Thank you. Yes yay yes. I studied mathematics. I've been programming for
15 years, 10-or-so professionally. I've always wanted a "real math"
explanation of monads.

They now make sense to me. Seeing why mu needs to go from T^2 -> T and the
role it plays concretely WRT the list and IO examples makes it really clear to
me.

God bless you for not using some crazy analogy like bacon or whatever.

~~~
nbouscal
Burritos! Monads are Burritos!
([http://byorgey.wordpress.com/2009/01/12/abstraction-
intuitio...](http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-
and-the-monad-tutorial-fallacy/))

------
cgag
"This assumes you are familiar with Haskell typeclasses and basic category
theory."

Where do I learn basic category theory? Anything better than just perusing
wikipedia?

~~~
johnsoncarity
A college CS or pure math course should cover it.

~~~
jfarmer
Hrm, not sure about that. I know of no college CS course that _requires_
category theory, let alone having the expectation that a decent CS degree will
give you exposure to it.

As an example, the University of Chicago, my alma mater, doesn't expose CS
students to Category Theory. Of all the places it might be where you's expect
it the most. It has a notoriously "theoretical" computer science department
tied closely to the mathematics department and _is where Category Theory was
invented_.

Even in a math degree, one wouldn't typically touch on Category Theory in a
classroom setting until one studied Algebraic Topology. Before that students
might come across it as a neat sideshow, but nothing they'd be interested in
using to solve an actual mathematical problem. There are plenty of students
who get a BS in mathematics without ever making a serious go at it.

It's also not really _that_ useful as a first-order field of mathematics. It's
mostly useful as a way of organizing other mathematical things and as I kind
of general vernacular. Even mathematicians sometimes lovingly call it
"abstract nonsense".

I see CT as a kind of mathematical interstate system. If you want to go back
and forth between Chicago to LA it's fantastic, but most of your work is being
done in Chicago or LA itself. The interstate system itself isn't _that_
interesting most of the time.

~~~
gjm11
Yes, I agree: you can easily do a bachelor's degree in either mathematics or
computer science without ever being taught category theory (though the chances
are you'd hear it mentioned a few times).

More specific evidence to go with _jfarmer_ 's: I read mathematics at the
University of Cambridge -- like UChicago, an absolutely first-rate institution
and not one that gives its students an easy ride -- and there category theory
is not part of the undergraduate curriculum. It is one of the courses you can
take in "Part III", which is a one-year taught master's degree[1].

[1] Until very recently, the best way to describe it was "a one-year taught
master's degree that inexplicably isn't actually a master's degree". But
they've fixed that now.

------
nilkn
I thought Hask was supposed to be the category of Haskell types with functions
between them. My Haskell is pretty rusty... how exactly does (->) resolve to
this meaning?

Also, on a more theoretical level, since Haskell types themselves belong to
the category Hask, by definition, to what extent can Haskell truly model
category theory when the objects of a category are evidently being represented
here as Haskell types?

~~~
quchen
1\. Hask has Haskell types as objects, and functions between them as
morphisms. "a" is a type, "b" is a type, and "a -> b" is an arrow between
them.

2\. Haskell cannot model (the entirety of) category theory. Everything in
Haskell is in Hask, and the only way to get to an entirely different category
(say Set) is on paper. This great talk gives some insight into the issue:
[https://vimeo.com/67174266](https://vimeo.com/67174266)

------
exDM69
I would like to give a word of encouragement to anyone who, like me, thought
this insight into Monads was all greek. Understanding any of the material in
this tutorial is not a prerequisite to writing practical computer programs in
Haskell.

You don't have to completely understand Monads in order to use them.

Just as you learn adding two numbers together in pre-school and learn about
axioms of associativity and commutativity later, you should start by learning
IO first and think about the more general ideas later.

Nevertheless, this was quite an interesting article. Maybe I'll try to put
some thought into it and see if I can learn something that would help me level
up my Haskell skills.

------
marshray
I love it! I just wish I understood it.

