This tutorial aims to explain the concept of a monad and its application to functional programming in a way that is easy to understand and useful to beginning and intermediate Haskell programmers. Familiarity with the Haskell language is assumed, but no prior experience with monads is required. The tutorial covers a lot of material and the later sections require a thorough understanding of the earlier material. Many code examples are provided along the way to demonstrate monadic programming. It is not advisable to attempt to absorb all of the material in a single reading.
The tutorial is arranged in three parts. The first part provides a basic understanding of the role of monads in functional programming, how monads operate, and how they are declared and used in Haskell. The second part covers each standard monad in Haskell, giving the definition of the monad and discussing the use of the monad. The third part covers advanced material relating to monad transformers and real-world issues encountered when programming with monads.
You can also download the complete tutorial as a compressed tar archive or as a zip archive.
The best way to really understand monads is to experiment with monadic code. This tutorial provides many code examples which range from simple to moderately complex, and you are encouraged to study them, play with them, modify them, etc. Unfortunately, it is necessary that the early examples must be contrived to avoid issues with combining multiple monads. If you find yourself frustrated by this restriction while experimenting with the example code, look ahead at Part III to see how it is overcome.
Please send any comments, corrections, or suggestions to Jeff Newbern at email@example.com