Changeset 6793 for src/Pugs/Prim/List.hs

Show
Ignore:
Timestamp:
09/06/05 14:11:41 (3 years ago)
Author:
autrijus
Message:

* massive retab for src/, expanding all tabs into spaces,

except for the generated PIL1.hs.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Prim/List.hs

    r4544 r6793  
    8585    -- or use the one of the user 
    8686    op1MinMax' min_or_max (Just subVal) valList = do 
    87           sub <- fromVal subVal 
    88           evl <- asks envEval 
    89           -- Here we execute the user's sub 
    90           foldM (\a b -> do 
    91               rv  <- local (\e -> e{ envContext = cxtItem "Int" }) $ do 
    92                   evl (App (Val sub) Nothing [Val a, Val b]) 
    93               int <- fromVal rv 
    94               -- If the return value from the sub was 
    95               --   -1 ==> a < b 
    96               --    0 ==> a == b 
    97               --   +1 ==> a > b 
    98               -- We call min_or_max so we can work for both min() and max(). 
    99               return $ if min_or_max (int > (0::VInt)) then a else b) (head valList) valList 
     87          sub <- fromVal subVal 
     88          evl <- asks envEval 
     89          -- Here we execute the user's sub 
     90          foldM (\a b -> do 
     91              rv  <- local (\e -> e{ envContext = cxtItem "Int" }) $ do 
     92                  evl (App (Val sub) Nothing [Val a, Val b]) 
     93              int <- fromVal rv 
     94              -- If the return value from the sub was 
     95              --   -1 ==> a < b 
     96              --    0 ==> a == b 
     97              --   +1 ==> a > b 
     98              -- We call min_or_max so we can work for both min() and max(). 
     99              return $ if min_or_max (int > (0::VInt)) then a else b) (head valList) valList 
    100100    -- This is the default comparision function, which will be used if the user 
    101101    -- hasn't specified a own comparision function. 
    102102    default_compare a b = do 
    103         a' <- vCastRat a 
    104         b' <- vCastRat b 
    105         let cmp = if a' < b' then (-1) else if a' == b' then 0 else 1 
    106         return $ if min_or_max (cmp > (0::VInt)) then a else b 
     103        a' <- vCastRat a 
     104        b' <- vCastRat b 
     105        let cmp = if a' < b' then (-1) else if a' == b' then 0 else 1 
     106        return $ if min_or_max (cmp > (0::VInt)) then a else b 
    107107 
    108108op1Uniq :: Val -> Eval Val 
     
    128128    -- Else, we have to write our own nubByM and use that. 
    129129    op1Uniq' (Just subVal) valList = do 
    130         sub <- fromVal subVal 
    131         evl <- asks envEval 
    132         -- Here we execute the user's sub 
    133         result <- nubByM (\a b -> do 
    134             rv  <- local (\e -> e{ envContext = cxtItem "Bool" }) $ do 
    135                 evl (App (Val sub) Nothing [Val a, Val b]) 
    136             -- The sub returns either true or false. 
    137             bool <- fromVal rv 
    138             return . VBool $ bool) valList 
    139         return . VList $ result 
     130        sub <- fromVal subVal 
     131        evl <- asks envEval 
     132        -- Here we execute the user's sub 
     133        result <- nubByM (\a b -> do 
     134            rv  <- local (\e -> e{ envContext = cxtItem "Bool" }) $ do 
     135                evl (App (Val sub) Nothing [Val a, Val b]) 
     136            -- The sub returns either true or false. 
     137            bool <- fromVal rv 
     138            return . VBool $ bool) valList 
     139        return . VList $ result 
    140140    -- This is the same as nubBy, only lifted into the Eval monad 
    141141    nubByM :: (Val -> Val -> Eval Val) -> [Val] -> Eval [Val] 
    142142    nubByM eq l = nubByM' l [] 
    143143      where 
    144         nubByM' [] _      = return [] 
    145         nubByM' (y:ys) xs = do 
    146             -- elemByM returns a Val, but we need a VBool, so we have to use fromVal. 
    147             cond <- fromVal =<< elemByM eq y xs 
    148             if cond then nubByM' ys xs else do 
    149                 result <- nubByM' ys (y:xs) 
    150                 return (y:result) 
    151         elemByM :: (Val -> Val -> Eval Val) -> Val -> [Val] -> Eval Val 
    152         elemByM _  _ []     = return . VBool $ False 
    153         elemByM eq y (x:xs) = do 
    154             cond <- fromVal =<< eq x y 
    155             -- Same here (we need a VBool, not a Var). 
    156             if cond then return . VBool $ cond else elemByM eq y xs 
     144        nubByM' [] _      = return [] 
     145        nubByM' (y:ys) xs = do 
     146            -- elemByM returns a Val, but we need a VBool, so we have to use fromVal. 
     147            cond <- fromVal =<< elemByM eq y xs 
     148            if cond then nubByM' ys xs else do 
     149                result <- nubByM' ys (y:xs) 
     150                return (y:result) 
     151        elemByM :: (Val -> Val -> Eval Val) -> Val -> [Val] -> Eval Val 
     152        elemByM _  _ []     = return . VBool $ False 
     153        elemByM eq y (x:xs) = do 
     154            cond <- fromVal =<< eq x y 
     155            -- Same here (we need a VBool, not a Var). 
     156            if cond then return . VBool $ cond else elemByM eq y xs 
    157157 
    158158op2FoldL :: Val -> Val -> Eval Val