shithub: MicroHs

ref: a29aeb7b470b51a212e225b7fe2d5233533b0269
dir: /tests/IOTest.hs/

View raw version
module IOTest(module IOTest) where
import Prelude
import System.IO as IO
import System.Environment
import Debug.Trace

f :: Int -> Int
f x = x*2+1

foo :: IO ()
foo = do
  putStrLn "foo 1"
  putStrLn "foo 2"

main :: IO ()
main = do
  tstart <- getTimeMilli
  putChar 'a'
  putChar 'b'
  c <- getChar
  putStrLn [c,c,c]
  let { p = putStrLn "hello" }
  p
  p
  p
  cprint ((+) :: Int->Int->Int)
  hout <- openFile "test.tmp" WriteMode
  hPutChar hout 'a'
  hPutChar hout 'z'
  hClose hout
  hin <- openFile "test.tmp" ReadMode
  c1 <- hGetChar hin
  c2 <- hGetChar hin
  putStrLn $ show (c1, c2)
  writeFile "test2.tmp" "more\n"
  s <- readFile "test2.tmp"
  putStrLn (show s)
  writeSerialized "f.tmp" f
  g <- readSerialized "f.tmp"
  putStrLn $ show $ (g (5::Int) :: Int)
  foo
  putStrLn $ show $ trace "tracing" (5::Int)
  as <- getArgs
  putStrLn $ show as
  putStrLn $ show $ seq ((1::Int) + (2::Int)) (5::Int)
  putStrLn $ show $ seq ((1::Int) + trace "seq" (2::Int)) (5::Int)
  tend <- getTimeMilli
  putStrLn $ show (tend - tstart) ++ "ms execution time"