Changeset 3904
- Timestamp:
- 05/26/05 11:56:40 (3 years ago)
- svk:copy_cache_prev:
- 5482
- Location:
- src/Pugs
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Eval.hs
r3901 r3904 676 676 doWhileUntil f = do 677 677 let [cond, body] = exps 678 enter Loop. fix $ \runLoop -> do678 enterWhile . fix $ \runLoop -> do 679 679 vbool <- enterEvalContext (cxtItem "Bool") cond 680 680 vb <- fromVal vbool … … 1181 1181 1182 1182 doFetch :: (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 1187 1188 doFetch fetchElem fetchVal fetchIdx isLV isSV = case (isLV, isSV) of 1188 1189 (True, True) -> do -
src/Pugs/Internals.hs
r3740 r3904 165 165 bytes = map (toEnum . ord) str 166 166 167 forM :: (Monad m) => [a] -> (a -> m b) -> m [b] 167 {-| 168 Take a list of values, and a monad-producing function, and apply that function 169 to each element of the list. The resulting monads are combined into a single 170 monad producing a list of the resulting values. 171 172 (This is just @mapM@ with the arguments reversed.) 173 -} 174 forM :: (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 168 178 forM = flip mapM 169 179 170 forM_ :: (Monad m) => [a] -> (a -> m b) -> m () 180 {-| 181 Take a list of values, and a monad-producing function, and apply that function 182 to each element of the list in sequence. The values produced by the monadic 183 function are discarded. 184 185 (This is just @mapM_@ with the arguments reversed.) 186 -} 187 forM_ :: (Monad m) 188 => [a] -- ^ List of values to loop over 189 -> (a -> m b) -- ^ The \'body\' of the for loop 190 -> m () 171 191 forM_ = flip mapM_ 172 192 … … 174 194 tryIO err = liftIO . (`catch` (const $ return err)) 175 195 176 combine :: [a->a] -> a -> a 196 {-| 197 Compose a list of @(a -> a)@ transformer functions into a single chained 198 function, using @foldr@ via the @(.)@ operator. 199 200 Note that the transformations are applied to the eventual argument in 201 right-to-left order. 202 -} 203 combine :: [a -> a] -- ^ List of transformer functions 204 -> (a -> a) -- ^ The final combined transformer 177 205 combine = foldr (.) id 178 206 … … 180 208 unsafePerformSTM = unsafePerformIO . atomically 181 209 182 modifyTVar :: TVar a -> (a -> a) -> STM () 210 {-| 211 Read an STM variable, apply some transformation function to it, and write the 212 transformed value back to the same variable. 213 -} 214 modifyTVar :: TVar a 215 -> (a -> a) 216 -> STM () 183 217 modifyTVar var f = do 184 218 x <- readTVar var … … 188 222 -- liftIO = unsafeIOToSTM 189 223 190 maybeM :: (FunctorM f, Monad m) => m (f a) -> (a -> m b) -> m (f b) 224 {-| 225 Extract a @Maybe@ value from the first argument (a monad). 226 227 If 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/ 229 wrapped in a @Just@. 230 231 Otherwise, 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 -} 236 maybeM :: (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@ 191 241 maybeM f m = fmapM m =<< f 192 242 193 243 {-| 194 Transform an operator name, for example @&infix: <+>@ or @&prefix:«[+]»@, into195 i ts internal name (@&infix:+@ and @&prefix:[+]@ respectively).244 Transform an operator name, for example @&infix:\<+\>@ or @&prefix:«[+]»@, 245 into its internal name (@&infix:+@ and @&prefix:[+]@ respectively). 196 246 -} 197 247 possiblyFixOperatorName :: String -> String -
src/Pugs/Monads.hs
r3740 r3904 92 92 } 93 93 94 enterLoop :: Eval Val -> Eval Val 95 enterLoop action = genSymCC "&last" $ \symLast -> do 94 {-| 95 Bind @&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 98 Note 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 100 test to the top of the body evaluation. 101 -} 102 enterWhile :: Eval Val -- ^ Evaluation representing loop test & body 103 -> Eval Val 104 enterWhile action = genSymCC "&last" $ \symLast -> do 96 105 genSymPrim "&next" (const action) $ \symNext -> do 97 106 enterLex [symLast, symNext] action … … 231 240 } ] 232 241 242 -- | (This doesn't seem to be used at the moment...) 233 243 caller :: Int -> Eval Env 234 244 caller n = do
