Name: Anonymous 2009-03-16 7:10
How are monads different than side effects?
bind and return. Each monad has its own specific bind function and its own specific return function. You can use monads as a way of abstracting "common computations". Monads can be also used to implement a sort of "container" for data. As for side effects in monads, you're probably thinking about the IO monad which can be thought of as a container that manages side effects to the real world.
"stupid" explanation, but it's still better than talking about triples and categories.Maybe, and yes, State.f(x) + g(y), their order of puts("lol") + puts("wut")? We can say thatputs("wut", puts("lol", world)). puts() depends on its second argument, so the internal puts(){Token1, Rest1} = parseShit(Input),
{Token2, Rest2} = parseShit(Rest1),
{Token3, Rest3} = parseShit(Rest2),
% do shit with Tokens, return {Result, Rest3}Token1 = parseShit(Monad),
Token2 = parseShit(Monad),
Token3 = parseShit(Monad),
% do shit with Tokens, return Result
,______ ___ ___ ____.,
/* ' ' ' \_
| \
- ~
| \
- |
/ \
- ________________________ \
. _ _/ \_ \ __.,._
. \.., / \,. *__/ \
'* / *
/ | /
\_ ,._.#####.__. .___#####._,. /- -.-
*,==| <._# )> vvvv <. # )> |==#" \
/ | | | | \ *
^_ | .,-* / \ | / /
/_ /\__________/ \_________/ - |
/ (__ __ ) | / \__,
| ** \ / " /.
" / \ \_- / /
\ / / v |
- | /
\ ,-''"''--"''"'-.. / \
\ \.,.-,.,.--,.../ |
\_ |
\_ _____ /.
.-/ <>>>____,.,..,____/ ___ / \
,./ \ .
,.*/ \ |\
* * \ /\
,.___/ | \ / |
\MAY THE FORCE BE WITH YOU YOUNG WIZARD
| -- G. J. Sussman
Monad is a typeclass. (That's kind of like an interface, in Java/C# parlance. You don't need OOP to have inheritance or polymorphism.) It has two methods you need to know about:return, which is totally unrelated to the C-family concept of return. It's a function that takes an arbitrary value and puts it into a monadic container. (Remember, it's just a function.)>>=, also known as bind, is a little more complicated. If you have a function foo that returns a monadic value (that is, a value that's been wrapped up by return) and a function bar that needs a single, unwrapped argument, you can write foo >>= bar to unwrap the return value of foo and pass it to bar.cat to read the file from disk and then pipe cat's output into your next command.cat sting_operations.txt | grep "child porn" | gzipreturn stingops >>= filter (contains "child porn") >>= compressreturn and >>= are different for every type that implements them, you can get completely different behavior depending on what type of container (that is, what instance of Monad) you're working with. I'm not going to try to explain why exactly that's the case, because it doesn't really make sense until you actually learn Haskell and see all the different kinds of things that monads are used for. The best I can do in a post on /prog/ is to give you some idea of what the hell you're looking at when you're confronted with one of the batshit monad tutorials strewn all over the internet (there are seriously over 9000 of them). So I didn't explain how to drive, but I did show you what all the pedals are for.Real World Haskell came out a couple months ago, and it contains an explanation of monads that doesn't say anything about math and just shows you how they work. #haskell was immediately mobbed by new people who haven't yet gone away.
PROVE ME WRONG
Computation", no one would find them so weird.
Warm Fuzzy Thing", no one would find them so weird. Appendable", no one would find them so weird.
State", no one would find them weird.side effects different than monads.