[Haskell-cafe] Monad explanation
jonathanccast at fastmail.fm
Wed Feb 4 16:22:01 EST 2009
On Wed, 2009-02-04 at 23:13 +0200, Tymur Porkuian wrote:
> Actually, I understand these types in terms of containers that
> override standard method of function application for their contents.
Huh? You can't actually over-ride function application --- Haskell's
built-in application always does exactly the same thing, at every type.
You can, however, define new application-like operators that have other
application-like behaviors. Haskell has a few of these:
> In fact, there may be no contents, or several items, or nothing at
> all, or something strange, but the container behaves like there is a
> value of some type inside it.
> In these terms:
> Maybe - container that may or may not contain something
> [a] - container that contains several values and applies function to all of them
> State - container that has some other "secondary" value in it.
> IO - container that remembers passed functions and later will ask user
> for value, then apply functions to it.
Nice but irrelevant. And I think your definition of IO is wrong.
> > * Monad: A monad M allows a function of n arguments (for n >= 0) to be
> > applied to n M values; in addition, if the function returns an M value
> > itself, you can combine that result with the arguments in a sensible
> > way.
> Here, what does "sensible" mean?
Sensible. As in, the definition of `join' in your monad can't be
senseless, or irrelevant to the monad's intended use.
> What do we override?
> Also, would it be right to say that Arrow is a container for functions
> that overrides function chaining?
More information about the Haskell-Cafe