# New monads

### From HaskellWiki

(added MonadSplit) |
(add Strict RWs) |
||

Line 16: | Line 16: | ||

It also defines BaseM which is like MonadBase above. | It also defines BaseM which is like MonadBase above. | ||

− | |||

− | |||

− | |||

− | |||

== MonadRandom == | == MonadRandom == | ||

Line 81: | Line 77: | ||

View [[New monads/MonadSplit]]. | View [[New monads/MonadSplit]]. | ||

+ | |||

+ | == Lazy and Strict variants == | ||

+ | |||

+ | This section contains monads that have interesting String or Lazy properties. | ||

+ | |||

+ | === LazyWriterT === | ||

+ | |||

+ | This came up on the mailing list: Why is WriterT never lazy? The answer is it does not use lazy patterns with "~". So here is a more useful [[New monads/LazyWriterT]] that add two "~" to the definition of (>>=) and renames WriterT to LazyWriterT. | ||

+ | |||

+ | === Strict RWS === | ||

+ | |||

+ | This was contribute by John Meacham on on the haskell-cafe mailing list. [[New monads/UnboxedRWS]] is an strict variant of RWS. | ||

[[Category:Idioms]] | [[Category:Idioms]] | ||

[[Category:Monad]] | [[Category:Monad]] |

## Revision as of 10:22, 12 January 2007

## Contents |

Remember to add a [ [ Category:Code ] ] tag to any new sub-pages.

## 1 MonadBase

It seems that the liftIO function from MonadIO can be generalized to access whatever the base of a transformer stack happens to be. So there is no need for a liftSTM, liftST, etc.

View New monads/MonadBase.

## 2 MonadLib

This is by Iavor S. Diatchki and can be found at http://www.cse.ogi.edu/~diatchki/monadLib/

It is a new version of the mtl package with transformers: ReaderT WriterT StateT ExceptT SearchT ContT

It also defines BaseM which is like MonadBase above.

## 3 MonadRandom

A simple monad transformer to allow computations in the transformed monad to generate random values.

View New monads/MonadRandom.

### 3.1 MonadRandomSplittable

A refinement of MonadRandom to integrate RandomGen's split function.

View at New monads/MonadRandomSplittable

## 4 MonadSupply

Here is a simple monad/monad transformer for computations which consume values from a (finite or infinite) supply. Note that due to pattern matching, running out of supply in a non-MonadZero monad will cause an error.

View New monads/MonadSupply.

## 5 MonadUndo

Here is a modified state monad transformer for keeping track of undo/redo states automatically.

View New monads/MonadUndo.

## 6 MonadUnique

This is a simple (trivial) monad transformer for supplying unique integer values to an algorithm.

View New monads/MonadUnique.

## 7 MonadSTO

Here's an extension of the ST monad in which the references are ordered and showable (they list their creation index).

View New monads/MonadSTO.

## 8 MonadAdvSTM

Here is an extension of STM to easy interaction with IO after committing or retrying. Inspired by Simon P-J.

View New monads/MonadAdvSTM.

## 9 TimedStateT

A monad transformer which combines State, Reader, and Error functionality to give the effect of a StateT monad which checks clock-time and stops the current computation if a period is exceeded.

darcs get http://www.mapcar.org/haskell/TimedStateT/

Haddocks: http://www.mapcar.org/haskell/TimedStateT/dist/doc/html/

## 10 MonadSplit

Represents the class of monads such that

l == (msplit l >>= \(x,xs) -> return x `mplus` xs)

In English, msplit is a counterpart to "mplus".

Using this, you can redefine many of the functions which previously depended on lists: foldM, scanM, inits, tails, and some derived functions.

View New monads/MonadSplit.

## 11 Lazy and Strict variants

This section contains monads that have interesting String or Lazy properties.

### 11.1 LazyWriterT

This came up on the mailing list: Why is WriterT never lazy? The answer is it does not use lazy patterns with "~". So here is a more useful New monads/LazyWriterT that add two "~" to the definition of (>>=) and renames WriterT to LazyWriterT.

### 11.2 Strict RWS

This was contribute by John Meacham on on the haskell-cafe mailing list. New monads/UnboxedRWS is an strict variant of RWS.