Changeset 3904

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

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

Location:
src/Pugs
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Eval.hs

    r3901 r3904  
    676676    doWhileUntil f = do 
    677677        let [cond, body] = exps 
    678         enterLoop . fix $ \runLoop -> do 
     678        enterWhile . fix $ \runLoop -> do 
    679679            vbool <- enterEvalContext (cxtItem "Bool") cond 
    680680            vb    <- fromVal vbool 
     
    11811181 
    11821182doFetch :: (Val -> Eval (IVar VScalar)) 
    1183             -> (Val -> Eval Val) 
    1184             -> (forall v. (Value v) => Eval v) 
    1185             -> Bool -> Bool 
    1186             -> Eval Val 
     1183        -> (Val -> Eval Val) 
     1184        -> (forall v. (Value v) => Eval v) 
     1185        -> Bool 
     1186        -> Bool 
     1187        -> Eval Val 
    11871188doFetch fetchElem fetchVal fetchIdx isLV isSV = case (isLV, isSV) of 
    11881189    (True, True) -> do 
  • 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 
  • src/Pugs/Monads.hs

    r3740 r3904  
    9292        } 
    9393 
    94 enterLoop :: Eval Val -> Eval Val 
    95 enterLoop action = genSymCC "&last" $ \symLast -> do 
     94{-| 
     95Bind @&last@ and @&next@ to subs that respectively break-out-of and repeat the  
     96@while@\/@until@, then perform the given evaluation in the new lexical scope. 
     97 
     98Note that this function is /not/ responsible for performing the actual 
     99@while@\/@until@ test; it is the responsibility of the caller to add such a 
     100test to the top of the body evaluation. 
     101-} 
     102enterWhile :: Eval Val -- ^ Evaluation representing loop test & body 
     103           -> Eval Val 
     104enterWhile action = genSymCC "&last" $ \symLast -> do 
    96105    genSymPrim "&next" (const action) $ \symNext -> do 
    97106        enterLex [symLast, symNext] action 
     
    231240        } ] 
    232241 
     242-- | (This doesn't seem to be used at the moment...) 
    233243caller :: Int -> Eval Env 
    234244caller n = do