Real World Haskell: Code You Can Believe In by Bryan O'Sullivan

Real World Haskell: Code You Can Believe In by Bryan O'Sullivan

Author:Bryan O'Sullivan [O'Sullivan, Bryan]
Language: eng
Format: azw3
Tags: COMPUTERS / Programming Languages / General
ISBN: 9780596156923
Publisher: O'Reilly Media
Published: 2008-11-15T05:00:00+00:00


Controlled Escape

The Monad typeclass doesn’t provide any means for values to escape their monadic shackles. We can inject a value into a monad using return. We can extract a value from a monad using (>>=) but the function on the right, which can see an unwrapped value, has to wrap its own result back up again.

Most monads have one or more runLogger-like functions. The notable exception is of course IO, which we usually escape from simply by exiting a program.

A monad execution function runs the code inside the monad and unwraps its result. Such functions are usually the only means provided for a value to escape from its monadic wrapper. The author of a monad thus has complete control over how whatever happens inside the monad gets out.

Some monads have several execution functions. In our case, we can imagine a few alternatives to runLogger: one might return only the log messages, whereas another might return just the result and drop the log messages.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.