Difference between revisions of "New monads"

From HaskellWiki
Jump to navigation Jump to search
m (NewMonads moved to New monads)
(Change links, add monad category)
Line 5: Line 5:
 
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.
 
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 [[NewMonads/MonadBase]].
+
View [[New monads/MonadBase]].
   
 
== MonadLib ==
 
== MonadLib ==
Line 17: Line 17:
 
== LazyWriterT ==
 
== 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 [[NewMonads/LazyWriterT]] that add two "~" to the definition of (>>=) and renames WriterT to 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.
   
 
== MonadRandom ==
 
== MonadRandom ==
Line 23: Line 23:
 
A simple monad transformer to allow computations in the transformed monad to generate random values.
 
A simple monad transformer to allow computations in the transformed monad to generate random values.
   
View [[NewMonads/MonadRandom]].
+
View [[New monads/MonadRandom]].
   
 
== MonadSupply ==
 
== MonadSupply ==
Line 29: Line 29:
 
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.
 
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 [[NewMonads/MonadSupply]].
+
View [[New monads/MonadSupply]].
   
 
== MonadUndo ==
 
== MonadUndo ==
Line 35: Line 35:
 
Here is a modified state monad transformer for keeping track of undo/redo states automatically.
 
Here is a modified state monad transformer for keeping track of undo/redo states automatically.
   
View [[NewMonads/MonadUndo]].
+
View [[New monads/MonadUndo]].
   
 
== MonadUnique ==
 
== MonadUnique ==
Line 41: Line 41:
 
This is a simple (trivial) monad transformer for supplying unique integer values to an algorithm.
 
This is a simple (trivial) monad transformer for supplying unique integer values to an algorithm.
   
View [[NewMonads/MonadUnique]].
+
View [[New monads/MonadUnique]].
   
 
== MonadSTO ==
 
== MonadSTO ==
Line 47: Line 47:
 
Here's an extension of the ST monad in which the references are ordered and showable (they list their creation index).
 
Here's an extension of the ST monad in which the references are ordered and showable (they list their creation index).
   
View [[NewMonads/MonadSTO]].
+
View [[New monads/MonadSTO]].
   
 
[[Category:Idioms]]
 
[[Category:Idioms]]
  +
[[Category:Monad]]

Revision as of 16:02, 7 October 2006

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.

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.

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.

MonadRandom

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

View New monads/MonadRandom.

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.

MonadUndo

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

View New monads/MonadUndo.

MonadUnique

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

View New monads/MonadUnique.

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.