Changeset 6672 for src/Pugs/Monads.hs

Show
Ignore:
Timestamp:
09/03/05 20:41:00 (3 years ago)
Author:
luqui
Message:

r548@feather: fibonaci | 2005-09-03 20:40:28 +0200
Rewrote findSyms to do real shadowing instead of returning all possible symbols. That is, if
there is a matching name in the lexical, it returns no global names. This solves the lexical
operator bug.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Monads.hs

    r5890 r6672  
    1818    enterBlock, enterSub, 
    1919    evalVal, tempVar, 
     20     
     21    MaybeT, runMaybeT, 
    2022 
    2123    module Control.Monad.RWS 
     
    2628import Pugs.Types 
    2729import Control.Monad.RWS 
     30 
     31 
     32newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) } 
     33 
     34instance (Monad m) => Monad (MaybeT m) where 
     35    (MaybeT mon) >>= f = 
     36        MaybeT (mon >>= maybe (return Nothing) (runMaybeT . f)) 
     37    return              = MaybeT . return . Just 
     38 
     39instance MonadTrans MaybeT where 
     40    lift mon = MaybeT (mon >>= return . Just) 
     41 
     42instance (Monad m) => MonadPlus (MaybeT m) where 
     43    mzero                       = MaybeT (return Nothing) 
     44    mplus (MaybeT a) (MaybeT b) = MaybeT $ do 
     45        ma <- a 
     46        mb <- b 
     47        return $ ma `mplus` mb 
     48 
    2849 
    2950{-|