Changeset 14925 for src/Pugs/Prim/List.hs
- Timestamp:
- 12/19/06 00:09:35 (2 years ago)
- Files:
-
- 1 modified
-
src/Pugs/Prim/List.hs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Prim/List.hs
r14478 r14925 4 4 op0Zip, op0Cat, op0Each, op0RoundRobin, op1Pick, op1Sum, 5 5 op1Min, op1Max, op1Uniq, 6 op2Pick, 6 7 op2ReduceL, op2Reduce, op2Grep, op2Map, op2Join, 7 8 sortByM, … … 57 58 else return undef 58 59 op1Pick v = retError "pick not defined" v 60 61 shuffle :: [a] -> Eval [a] 62 shuffle [] = return [] 63 shuffle xs = do 64 -- pick the first element 65 first <- liftIO $ randomRIO (0 :: Int, length xs - 1) 66 rest <- shuffle $ take first xs ++ drop (first+1) xs 67 return $ head (drop first xs) : rest 68 69 op2Pick :: Val -> Val -> Eval Val 70 op2Pick (VRef r) num = do 71 ref <- readRef r 72 op2Pick ref num 73 op2Pick (VList xs) (VInt num) = do 74 shuffled <- shuffle xs 75 return $ VList $ take (fromInteger num) shuffled 76 op2Pick r _ = retError "pick not defined" r 59 77 60 78 op1Sum :: Val -> Eval Val
