import Random -- generate random input files of various sizes for the additive parser generateRandom :: Int -> IO String generateRandom x = ans x >>= return . ($ []) where ans x = do r <- randomIO case abs r `mod` 7 :: Int of 1 -> do s <- ans x return (showString "(" . s . showString ")") 2 -> do s1 <- ans (x - 1) s2 <- ans (x - 1) return (s1 . showString "*" . s2) 3 -> do s1 <- ans (x - 1) s2 <- ans (x - 1) return (s1 . showString "+" . s2) _ | x < 0 -> do n <- randomIO return (shows (n `mod` 256::Int)) _ -> ans x main = do flip mapM_ [2 .. 15] $ \x -> do s <- generateRandom x let fn = "test" ++ show x ++ ".txt" putStrLn $ "Writing '" ++ fn ++ "'" writeFile fn s