Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'll have my stab at making a short explanation without code or lots of technical stuff. So here's some handwaving that may contain mistakes:

Monads are sequential processes, which are combined to make bigger processes. getLine is a monad, so is putStrLn "hello". You can combine two monads into a bigger monad using the >>= operator, which would be the "means of combination" which is extensively discussed in the Structure and Interpretation of Computer Programs lectures. Simplest monad program I can think of is echo = getLine >>= putStrLn.

I learned monads by doing simple stuff like guess the number and hangman, first writing them in the do-notation (syntactic sugar for a mini-imperative language) and then converting that to concrete notation using >>=.

Monads are not only useful for IO, but also other sequential processes such as parsing, pretty printing, binary file io and stateful inside but functional outside algorithms (ST monad).

Disclaimer: this was written by a Haskell newb, recently introduced to the wonderful world of Monads.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: