Changeset 16602

Show
Ignore:
Timestamp:
06/01/07 21:29:00 (18 months ago)
Author:
audreyt
Message:

* Pugs.Monads: Add MonadIO instance to the MaybeT monad.

Also simplify the mplus operation so the second action
is only run when the first operation returns Nothing.
(It used to run both and then needlessly discards the second.)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Monads.hs

    r16487 r16602  
    4343    lift mon = MaybeT (mon >>= return . Just) 
    4444 
     45instance (MonadIO m) => MonadIO (MaybeT m) where 
     46    liftIO ma = MaybeT $ do 
     47        a <- liftIO ma 
     48        return (Just a) 
     49 
    4550instance (Monad m) => MonadPlus (MaybeT m) where 
    4651    mzero                       = MaybeT (return Nothing) 
    4752    mplus (MaybeT a) (MaybeT b) = MaybeT $ do 
    4853        ma <- a 
    49         mb <- b 
    50         return $ ma `mplus` mb 
     54        case ma of 
     55            Nothing -> b 
     56            _       -> return ma  
    5157 
    5258{-|