Changeset 3904 for src/Pugs/Internals.hs

Show
Ignore:
Timestamp:
05/26/05 11:56:40 (4 years ago)
Author:
scook0
svk:copy_cache_prev:
5482
Message:

* Haddocks for Internals.hs
* Renamed 'enterLoop' to 'enterWhile'

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Internals.hs

    r3740 r3904  
    165165    bytes = map (toEnum . ord) str 
    166166 
    167 forM :: (Monad m) => [a] -> (a -> m b) -> m [b] 
     167{-| 
     168Take a list of values, and a monad-producing function, and apply that function 
     169to each element of the list. The resulting monads are combined into a single 
     170monad producing a list of the resulting values. 
     171 
     172(This is just @mapM@ with the arguments reversed.) 
     173-} 
     174forM :: (Monad m)  
     175     => [a]        -- ^ List of values to loop over 
     176     -> (a -> m b) -- ^ The \'body\' of the for loop 
     177     -> m [b]      -- ^ Monad containing a list of the results 
    168178forM = flip mapM 
    169179 
    170 forM_ :: (Monad m) => [a] -> (a -> m b) -> m () 
     180{-| 
     181Take a list of values, and a monad-producing function, and apply that function 
     182to each element of the list in sequence. The values produced by the monadic 
     183function are discarded. 
     184 
     185(This is just @mapM_@ with the arguments reversed.) 
     186-} 
     187forM_ :: (Monad m)  
     188      => [a]        -- ^ List of values to loop over 
     189      -> (a -> m b) -- ^ The \'body\' of the for loop 
     190      -> m () 
    171191forM_ = flip mapM_ 
    172192 
     
    174194tryIO err = liftIO . (`catch` (const $ return err)) 
    175195 
    176 combine :: [a->a] -> a -> a 
     196{-| 
     197Compose a list of @(a -> a)@ transformer functions into a single chained 
     198function, using @foldr@ via the @(.)@ operator. 
     199 
     200Note that the transformations are applied to the eventual argument in  
     201right-to-left order. 
     202-} 
     203combine :: [a -> a] -- ^ List of transformer functions 
     204        -> (a -> a) -- ^ The final combined transformer 
    177205combine = foldr (.) id 
    178206 
     
    180208unsafePerformSTM = unsafePerformIO . atomically 
    181209 
    182 modifyTVar :: TVar a -> (a -> a) -> STM () 
     210{-| 
     211Read an STM variable, apply some transformation function to it, and write the 
     212transformed value back to the same variable. 
     213-} 
     214modifyTVar :: TVar a  
     215           -> (a -> a)  
     216           -> STM () 
    183217modifyTVar var f = do 
    184218    x <- readTVar var 
     
    188222--     liftIO = unsafeIOToSTM 
    189223 
    190 maybeM :: (FunctorM f, Monad m) => m (f a) -> (a -> m b) -> m (f b) 
     224{-| 
     225Extract a @Maybe@ value from the first argument (a monad). 
     226 
     227If it's a @Just@ (i.e. it contains a value), apply the second argument 
     228(a monad-producing function) to it, and @return@ the contents of /that/  
     229wrapped in a @Just@. 
     230 
     231Otherwise, merely @return Nothing@. 
     232 
     233(Strictly speaking, this function can operate with any @FunctorM@, not just 
     234@Maybe@, but it helps to have a concrete example to explain things.) 
     235-} 
     236maybeM :: (FunctorM f, Monad m)  
     237       => m (f a)    -- ^ A @Maybe@ value encapsulated in a monad 
     238       -> (a -> m b) -- ^ Action to perform on the first arg /if/ it contains 
     239                     --     a value 
     240       -> m (f b)    -- ^ Monad containing (@Just@ /result/) or @Nothing@ 
    191241maybeM f m = fmapM m =<< f 
    192242 
    193243{-| 
    194 Transform an operator name, for example @&infix:<+>@ or @&prefix:«[+]»@, into 
    195 its internal name (@&infix:+@ and @&prefix:[+]@ respectively). 
     244Transform an operator name, for example @&infix:\<+\>@ or @&prefix:«[+]»@,  
     245into its internal name (@&infix:+@ and @&prefix:[+]@ respectively). 
    196246-} 
    197247possiblyFixOperatorName :: String -> String