Ticket #1127: proposal-1127-2.diff

File proposal-1127-2.diff, 5.1 KB (added by igloo, 9 years ago)
  • Control/Monad/Error.hs

    Wed Jan 31 12:41:39 GMT 2007  Ian Lynagh <[email protected]>
      * Make mtl lazier; trac proposal #1127
    diff -rN -u old-mtl/Control/Monad/Error.hs new-mtl/Control/Monad/Error.hs
    old new  
    225225instance (Error e, MonadWriter w m) => MonadWriter w (ErrorT e m) where
    226226        tell     = lift . tell
    227227        listen m = ErrorT $ do
    228                 (a, w) <- listen (runErrorT m)
     228                ~(a, w) <- listen (runErrorT m)
    229229                return $ case a of
    230230                        Left  l -> Left  l
    231231                        Right r -> Right (r, w)
  • Control/Monad/RWS.hs

    diff -rN -u old-mtl/Control/Monad/RWS.hs new-mtl/Control/Monad/RWS.hs
    old new  
    100100
    101101instance (Monad m) => Functor (RWST r w s m) where
    102102        fmap f m = RWST $ \r s -> do
    103                 (a, s', w) <- runRWST m r s
     103                ~(a, s', w) <- runRWST m r s
    104104                return (f a, s', w)
    105105
    106106instance (Monoid w, Monad m) => Monad (RWST r w s m) where
    107107        return a = RWST $ \_ s -> return (a, s, mempty)
    108108        m >>= k  = RWST $ \r s -> do
    109                 (a, s', w)  <- runRWST m r s
    110                 (b, s'',w') <- runRWST (k a) r s'
     109                ~(a, s', w)  <- runRWST m r s
     110                ~(b, s'',w') <- runRWST (k a) r s'
    111111                return (b, s'', w `mappend` w')
    112112        fail msg = RWST $ \_ _ -> fail msg
    113113
     
    125125instance (Monoid w, Monad m) => MonadWriter w (RWST r w s m) where
    126126        tell   w = RWST $ \_ s -> return ((),s,w)
    127127        listen m = RWST $ \r s -> do
    128                 (a, s', w) <- runRWST m r s
     128                ~(a, s', w) <- runRWST m r s
    129129                return ((a, w), s', w)
    130130        pass   m = RWST $ \r s -> do
    131                 ((a, f), s', w) <- runRWST m r s
     131                ~((a, f), s', w) <- runRWST m r s
    132132                return (a, s', f w)
    133133
    134134instance (Monoid w, Monad m) => MonadState s (RWST r w s m) where
     
    146146
    147147evalRWST :: (Monad m) => RWST r w s m a -> r -> s -> m (a, w)
    148148evalRWST m r s = do
    149     (a, _, w) <- runRWST m r s
     149    ~(a, _, w) <- runRWST m r s
    150150    return (a, w)
    151151
    152152execRWST :: (Monad m) => RWST r w s m a -> r -> s -> m (s, w)
    153153execRWST m r s = do
    154     (_, s', w) <- runRWST m r s
     154    ~(_, s', w) <- runRWST m r s
    155155    return (s', w)
    156156
    157157mapRWST :: (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
  • Control/Monad/State.hs

    diff -rN -u old-mtl/Control/Monad/State.hs new-mtl/Control/Monad/State.hs
    old new  
    186186
    187187instance (Monad m) => Functor (StateT s m) where
    188188        fmap f m = StateT $ \s -> do
    189                 (x, s') <- runStateT m s
     189                ~(x, s') <- runStateT m s
    190190                return (f x, s')
    191191
    192192instance (Monad m) => Monad (StateT s m) where
    193193        return a = StateT $ \s -> return (a, s)
    194194        m >>= k  = StateT $ \s -> do
    195                 (a, s') <- runStateT m s
     195                ~(a, s') <- runStateT m s
    196196                runStateT (k a) s'
    197197        fail str = StateT $ \_ -> fail str
    198198
     
    224224instance (MonadWriter w m) => MonadWriter w (StateT s m) where
    225225        tell     = lift . tell
    226226        listen m = StateT $ \s -> do
    227                 ((a, s'), w) <- listen (runStateT m s)
     227                ~((a, s'), w) <- listen (runStateT m s)
    228228                return ((a, w), s')
    229229        pass   m = StateT $ \s -> pass $ do
    230                 ((a, f), s') <- runStateT m s
     230                ~((a, f), s') <- runStateT m s
    231231                return ((a, s'), f)
    232232
    233233-- |Similar to 'evalState'
    234234evalStateT :: (Monad m) => StateT s m a -> s -> m a
    235235evalStateT m s = do
    236         (a, _) <- runStateT m s
     236        ~(a, _) <- runStateT m s
    237237        return a
    238238
    239239-- |Similar to 'execState'
    240240execStateT :: (Monad m) => StateT s m a -> s -> m s
    241241execStateT m s = do
    242         (_, s') <- runStateT m s
     242        ~(_, s') <- runStateT m s
    243243        return s'
    244244
    245245-- |Similar to 'mapState'
  • Control/Monad/Writer.hs

    diff -rN -u old-mtl/Control/Monad/Writer.hs new-mtl/Control/Monad/Writer.hs
    old new  
    6464
    6565listens :: (MonadWriter w m) => (w -> b) -> m a -> m (a, b)
    6666listens f m = do
    67         (a, w) <- listen m
     67        ~(a, w) <- listen m
    6868        return (a, f w)
    6969
    7070censor :: (MonadWriter w m) => (w -> w) -> m a -> m a
     
    111111
    112112instance (Monad m) => Functor (WriterT w m) where
    113113        fmap f m = WriterT $ do
    114                 (a, w) <- runWriterT m
     114                ~(a, w) <- runWriterT m
    115115                return (f a, w)
    116116
    117117instance (Monoid w, Monad m) => Monad (WriterT w m) where
    118118        return a = WriterT $ return (a, mempty)
    119119        m >>= k  = WriterT $ do
    120                 (a, w)  <- runWriterT m
    121                 (b, w') <- runWriterT (k a)
     120                ~(a, w)  <- runWriterT m
     121                ~(b, w') <- runWriterT (k a)
    122122                return (b, w `mappend` w')
    123123        fail msg = WriterT $ fail msg
    124124
     
    132132instance (Monoid w, Monad m) => MonadWriter w (WriterT w m) where
    133133        tell   w = WriterT $ return ((), w)
    134134        listen m = WriterT $ do
    135                 (a, w) <- runWriterT m
     135                ~(a, w) <- runWriterT m
    136136                return ((a, w), w)
    137137        pass   m = WriterT $ do
    138                 ((a, f), w) <- runWriterT m
     138                ~((a, f), w) <- runWriterT m
    139139                return (a, f w)
    140140
    141141instance (Monoid w) => MonadTrans (WriterT w) where
     
    155155
    156156execWriterT :: Monad m => WriterT w m a -> m w
    157157execWriterT m = do
    158         (_, w) <- runWriterT m
     158        ~(_, w) <- runWriterT m
    159159        return w
    160160
    161161mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b