1 2 3 4 5 6 7 8 9 10 11 12 module Utils ( 13 cmap, rep, print_str, split_str, finish 14 ) where 15 16 import Char 17 import Config 18 import Types 19 import Env 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 cmap :: [(Xcont x) -> Cont] -> (Xscont x) -> Cont 43 cmap [] xsc = xsc [] 44 cmap (xc:xcs) xsc = xc (cmap xcs . (.) xsc . (:)) 45 46 47 48 49 50 51 52 rep :: Int -> x -> [x] 53 rep n x = take n (repeat x) 54 55 56 57 58 59 60 61 print_str :: String -> Cont -> Cont 62 print_str s c = get_output (\ op e -> op s >> c e) 63 64 65 66 67 68 69 70 71 72 73 split_str :: Int -> String -> String 74 split_str n "" = "" 75 split_str n s = start ++ next ++ "\n" 76 ++ split_str n (dropWhile isSpace rest) 77 where 78 (start, rest1) = split_num n s 79 (next, rest) = span (not . isSpace) rest1 80 split_num 0 s = ("", s) 81 split_num _ "" = ("", "") 82 split_num _ ('\n':cs) = ("", ' ':cs) 83 split_num m (c:cs) = (c:cs', cs'') 84 where 85 (cs',cs'') = split_num (m-one) cs 86 87 88 89 90 91 92 finish :: Cont 93 finish e = return () 94 95