Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
0 of .
Results for:
P. 1

Ratings: (0)|Views: 72 |Likes:

### Availability:

See more
See less

01/21/2014

pdf

text

original

Next:Introduction
A comprehensive guide to the theory and practice of monadic programming in Haskell
Unfortunately, it is necessary that theearly examples must be contrived to avoid issues with combining multiple monads. If you find yourself frustrated by this restriction whileexperimenting 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 jnewbern@yahoo.com
Contents
Part II - A Catalog of Standard Monads

Part III - Monads in the Real World
Appendices
Appendix I - A physical analogy for monadsAppendix II - Haskell code examplesNext:Introduction

Introduction
Introduction
What is a monad?Why should I make the effort to understand monads?
A monad is a way to structure computations in terms of values and sequences of computations using those values. Monads allow the programmerto build up computations using sequential building blocks, which can themselves be sequences of computations. The monad determines howcombined computations form a new computation and frees the programmer from having to code the combination manually each time it isrequired.
It is useful to think of a monad as a strategy for combining computations into more complex computations.
For example, you should be familiarwith the
Maybe
data Maybe a = Nothing | Just a
which represents the type of computations which may fail to return a result. The
Maybe
type suggests a strategy for combining computationswhich return
Maybe
values: if a combined computation consists of one computation
B
that depends on the result of another computation
A
, thenthe combined computation should yield
Nothing
whenever either
A
or
B
yield
Nothing
and the combined computation should yield the result of
B
applied to the result of
A
when both computations succeed.Other monads exist for building computations that perform I/O, have state, may return multiple results, etc. There are as many different type of monads as there are strategies for combining computations, but there are certain monads that are especially useful and are common enough thatthey are part of the standardHaskell 98 libraries. These monads are each described inPart II.
Why should I make the effort to understand monads?