views:

1407

answers:

5
+3  Q: 

What are monads?

everyone keeps talking about monads and monadic style and Haskell. i can't find much information or tutorial on haskell monads.

+10  A: 

I don't think you mean nomad. Try monad instead!

ChrisN
But "Nomadic Haskell Programming" has a much more romantic ring to it, they should change the name!
Victor
Yes. I'm picturing gray-cloaked, bearded tribes wandering through the dust and ruin, spreading functional programming along their route.
Shog9
Actually, Shog9, they wouldn't have any side effects ;)
Cody Brocious
@Cody: hah! good point.
Shog9
+3  A: 

Well, "nomads" are people who wander from place to place. I assume you mean "monads". :-)

That's a very tricky question. Wikipedia has some information, and tons of tutorials are available around the web.. In a nutshell, a monad is a type constructor with associated functions which behave according to certain laws. Incidentally, a type constructor is what languages like Java or C++ might call a generic instantiation (e.g. List<String>). The two main monadic methods:

  • unit - Wraps up the relevant data within an instance of the monad. For example, the unit function for the Option monad in Scala would be used as follows: Some(42).
  • bind - This is the important (and confusing) one. This function has the following signature for some monadic type M: bind(M[A], (A)=>M[B]): M[B]. Thus, it is a function which takes a monad of "component type" A, unwraps it and passes the value to the specified function value, which returns another instance of the monad with component type B. The final result of the function is a (possibly the returned) instance of the monad with component type B.

The applications of monads are almost innumerable; they are quite literally everywhere, even in imperative languages. If you actually play around with Haskell a bit, you'll find yourself using them constantly. That's probably the best way to get a handle on them: see how they're used in real-world algorithm design.

Daniel Spiewak
+5  A: 

Nomadic people, (from the Greek: νομάδες, nomádes, "those who let pasture herds"), also known as nomads, are communities of people that move with cattle from one place to another, rather than settling down in one location. They aren't renown for their coding abilities, reliable electricity being hard for them to come by, but give them a place to plug their laptops into and they'll soon be hammering away on their keyboards. In fact, early powersaving support was added to Linux by an anonymous desert wanderer, and the hobo community of Los Angeles were responsible for roaming support in FreeBSD.

Jim
You insensitive clod, everyone knows that 'monad' is singular for 'gonad'.
Scott Smith
+1  A: 

Why you shouldn't ask what a monad is.

Greg Bacon