https://wiki.haskell.org/index.php?title=New_monads/MonadBase&feed=atom&action=history
New monads/MonadBase - Revision history
2024-03-19T07:26:17Z
Revision history for this page on the wiki
MediaWiki 1.35.5
https://wiki.haskell.org/index.php?title=New_monads/MonadBase&diff=7351&oldid=prev
ChrisKuklewicz at 18:07, 26 October 2006
2006-10-26T18:07:43Z
<p></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:07, 26 October 2006</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td>
</tr>
<tr>
<td colspan="2" class="diff-empty"> </td>
<td class="diff-marker">+</td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Code]]</div></td>
</tr>
<tr>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>From New monads</div></td>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>From New monads</div></td>
</tr>
<tr>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td>
</tr>
<!-- diff cache key wikidb_haskell:diff:wikidiff2:1.12:old-6585:rev-7351:1.10.0 -->
</table>
ChrisKuklewicz
https://wiki.haskell.org/index.php?title=New_monads/MonadBase&diff=6585&oldid=prev
BrettGiles: Remove redundant link
2006-10-07T16:03:59Z
<p>Remove redundant link</p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 16:03, 7 October 2006</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td>
</tr>
<tr>
<td class="diff-marker">−</td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>From <del class="diffchange diffchange-inline">[[NewMonads]]</del></div></td>
<td class="diff-marker">+</td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>From <ins class="diffchange diffchange-inline">New monads</ins></div></td>
</tr>
<tr>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td>
</tr>
<tr>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>= MonadBase =</div></td>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>= MonadBase =</div></td>
</tr>
</table>
BrettGiles
https://wiki.haskell.org/index.php?title=New_monads/MonadBase&diff=6568&oldid=prev
BrettGiles: NewMonads/MonadBase moved to New monads/MonadBase
2006-10-07T15:57:58Z
<p>NewMonads/MonadBase moved to New monads/MonadBase</p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:57, 7 October 2006</td>
</tr>
<!-- diff cache key wikidb_haskell:diff:wikidiff2:1.12:old-5657:rev-6568:1.10.0 -->
</table>
BrettGiles
https://wiki.haskell.org/index.php?title=New_monads/MonadBase&diff=5657&oldid=prev
ChrisKuklewicz at 17:10, 24 August 2006
2006-08-24T17:10:17Z
<p></p>
<p><b>New page</b></p><div>From [[NewMonads]]<br />
<br />
= MonadBase =<br />
<br />
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.<br />
<br />
<haskell><br />
-- By Chris Kuklewicz<br />
module MonadBase(MonadBase,liftBase,MonadIO',liftIO') where<br />
<br />
import Data.Monoid(Monoid)<br />
import Control.Monad.Trans(lift,MonadTrans)<br />
-- All the base monads with GHC<br />
import Control.Monad.ST.Strict as S(ST)<br />
import Control.Monad.ST.Lazy as L(ST)<br />
import Control.Concurrent.STM(STM)<br />
import Control.Monad.Identity(Identity)<br />
import Text.ParserCombinators.Parsec(GenParser)<br />
-- And all the MonadIO instances:<br />
import Control.Monad.List(ListT)<br />
import Control.Monad.Cont(ContT)<br />
import Control.Monad.Error(ErrorT,Error)<br />
import Control.Monad.Reader(ReaderT)<br />
import Control.Monad.State(StateT)<br />
import Control.Monad.Writer(WriterT)<br />
import Control.Monad.RWS(RWST)<br />
<br />
class (Monad m,Monad b) => MonadBase b m where<br />
liftBase :: b a -> m a<br />
<br />
-- One can recover MonadIO and liftIO from MonadBase<br />
class (MonadBase IO m) => MonadIO' m where<br />
liftIO' :: IO a -> m a<br />
liftIO' = liftBase<br />
<br />
-- Base monads<br />
instance MonadBase IO IO where liftBase = id<br />
instance MonadBase STM STM where liftBase = id<br />
instance MonadBase (GenParser tok st) (GenParser tok st) where liftBase = id<br />
instance MonadBase (S.ST s) (S.ST s) where liftBase = id<br />
instance MonadBase (L.ST s) (L.ST s) where liftBase = id<br />
instance MonadBase Maybe Maybe where liftBase = id<br />
instance MonadBase [] [] where liftBase = id<br />
instance (Error e) => MonadBase (Either e) (Either e) where liftBase = id<br />
instance MonadBase ((->) a) ((->) a) where liftBase = id<br />
instance MonadBase Identity Identity where liftBase = id<br />
<br />
-- Trans monads<br />
instance MonadBase b m => MonadBase b (ListT m) where<br />
liftBase = lift . liftBase<br />
instance MonadBase b m => MonadBase b (ContT r m) where<br />
liftBase = lift . liftBase<br />
instance (Error e, MonadBase b m) => MonadBase b (ErrorT e m) where<br />
liftBase = lift . liftBase<br />
instance MonadBase b m => MonadBase b (ReaderT r m) where<br />
liftBase = lift . liftBase<br />
instance MonadBase b m => MonadBase b (StateT s m) where<br />
liftBase = lift . liftBase<br />
instance (Monoid w, MonadBase b m) => MonadBase b (WriterT w m) where<br />
liftBase = lift . liftBase<br />
instance (Monoid w, MonadBase b m) => MonadBase b (RWST r w s m) where<br />
liftBase = lift . liftBase<br />
</haskell><br />
<br />
And an artificial example:<br />
<br />
<haskell><br />
module Main where<br />
<br />
import MonadBase<br />
import Control.Monad.Reader<br />
import Control.Monad.Writer<br />
type Foo a = (WriterT [Int] (ReaderT String [])) a<br />
<br />
foo :: Foo String<br />
foo = do<br />
x <- liftBase [1,2,3]<br />
s <- ask<br />
tell [succ x]<br />
return (s ++ show x)<br />
<br />
test = runReaderT (runWriterT foo) "hello"<br />
</haskell><br />
<br />
<pre><br />
*Main> test<br />
[("hello1",[2]),("hello2",[3]),("hello3",[4])]<br />
</pre></div>
ChrisKuklewicz