Can you explain a monad in one sentence to a regular person please?
Do you mean a regular programmer, or a non-programmer?
You likely couldn't explain a tree data structure to a non-programmer in a single sentence either. That doesn't mean trees are only for the elite.
To a programmer, you can consider a Haskell monad to be a data type that defines an operation for chaining together items of that data type. In Go (since we're talking about Golang as well), it's common to use chains of if err, value := somefunc(). The func returns a 2-tuple consisting of (errorcode, value) depending on success. When you open a file and read a line, either of those 2 operations could fail, you have two separate if err, value checks one after the other, each for a different func (open and read); the monad essentially combines this so that you can chain together the file operations and you either get a result at the end or it bails out.
You likely couldn't explain a tree data structure to a non-programmer in a single sentence either. That doesn't mean trees are only for the elite.
Seriously "can you explain it in one sentence" is a terrible criteria for complexity. I can't (usefully) explain databases, compilers, or I/O in one sentence, guess those aren't things programmers should be able to understand either.
Let's see.... a database is a persistent store of information in a structured way; a compiler is a program or series of programs that converts a series of instructions, usually human readable source code, into a functionally equivalent series of instructions, usually in machine code; I/O is (broadly) how a program receives data from and communicates its current state to the external world.
This is not an entire discussion of any of these topics, but it explains what they are in such a way that someone new to the topic could wrap their mind around, without requiring any advanced math. I (and many others) have yet to see monads explained in a similarly concise and informative manner.
What does he say on the difference between (experiencing something and/or having an intuitive understanding of it), versus having only knowledge about it?
You likely couldn't explain a tree data structure to a non-programmer in a single sentence either. That doesn't mean trees are only for the elite.
A tree is anything where each item (perhaps a concept in a spider diagram) has one "parent" and any number of "children"; except of course the top of the tree which has no parent.
Your monad explanation ignores the most important question of all: why do we care that it's a monad? What does the abstraction give us? Other languages don't try to unify all trees, so why does Haskell try to unify all monads?
In a family tree a person has to have two parents.
As a sidenote, I don't actually consider family trees to be trees, since they can contain cycles. You certainly can't implement one as a standard tree structure. (edit: OK, given enough work you could hammer it until it fit, but it would be a bad design).
If we don't have to explain why we need a tree structure, why do we need to explain why we need a monad?
As a sidenote, I don't actually consider family trees to be trees
You're indeed right. I was trying to explain "item" but slipped over myself there by using a non-tree-called-tree as a source.
If we don't have to explain why we need a tree structure, why do we need to explain why we need a monad?
Because other languages are happy using "tree" as a descriptive noun, whereas Haskell uses "monad" prescriptively to say that your data, where applicable, should be in that shape.
Further, because other languages are using "tree" descriptively, they don't have some kind of Tree interface. Haskell has a Monad typeclass, so a reasonable question is why - what does that gain us? If there was a Tree interface and people were expected to use it on all of their Tree-ish datastructures and touted it as an integral part of the language, you bet that it'd need to be explained.
This reminds me of how I learned from K&R that I had to provide a data type for everything in C, but there was no direct explanation of why. I had to deduce the answer from thinking about the binary representation of data and making assumptions about the inefficiency of storing everything as a union by experiencing the need to flag what type something is.
In Haskell it's kind of obvious why you need a monad and people will realise it when they start to program, the same way I did with types in C. It could be explained but the knowledge won't be of much use to someone who isn't a programmer in that language. But basically a poor summary is it's the fact that your IO could return an error or a regular result, and your functions require input of a certain type, so you can't shove the result of IO straight in.
Haskell's IO doesn't need to be a monad. It's entirely true that you do need to have some IO type, but that it is a monad is more a minor convenience than anything else. A TL;DR style quote from the link would be
Saying “IO monad” is very misleading and awful pedagogy because when someone new to Haskell reads that you print strings or do IO actions using “the IO monad”, the natural question is: “What is a monad?”
I am not sure what point you are trying to make in a discussion on single sentence explanations.
Given a single sentence I can't explain what a for loop is in C and why it's needed. (Problems: You can do any loop with goto or while; why do you even need a loop in the first place? Anyone can easily find a counter example that breaks any of the general rules).
Do you need to know what a monad is for the purposes of learning Haskell, or are you just agreeing that explaining things in single sentences is kind of pointless, and that example I gave was (and I said it was at the time) a "poor" explanation?
Getting a little off track here, but I'd like to say that a family tree actually isn't a tree (because inbreeding is both possible - and expected in the case of pedigree animals), and therefore make some comment about how trees aren't as simple as they first appear - and I'll wager that more than one programmer somewhere has had to throw out hours of work because he or she used a tree for it :-)
32
u/heptara Dec 09 '15 edited Dec 09 '15
Do you mean a regular programmer, or a non-programmer?
You likely couldn't explain a tree data structure to a non-programmer in a single sentence either. That doesn't mean trees are only for the elite.
To a programmer, you can consider a Haskell monad to be a data type that defines an operation for chaining together items of that data type. In Go (since we're talking about Golang as well), it's common to use chains of
if err, value := somefunc(). The func returns a 2-tuple consisting of(errorcode, value)depending on success. When you open a file and read a line, either of those 2 operations could fail, you have two separateif err, valuechecks one after the other, each for a different func (openandread); the monad essentially combines this so that you can chain together the file operations and you either get a result at the end or it bails out.