Main.agda 810 B

12345678910111213141516171819202122232425262728293031323334
  1. module Main where
  2. {-# IMPORT System.IO #-}
  3. {-# IMPORT System.Environment #-}
  4. open import Base
  5. open import IO
  6. open import IO.File
  7. postulate
  8. getArgs : IO (List String)
  9. {-# COMPILED getArgs getArgs #-}
  10. _`bindIO`_ : {A B : Set} -> IO A -> (A -> IO B) -> IO B
  11. _`bindIO`_ = bindIO
  12. main : IO Unit
  13. main = getArgs `bindIO` mainWithArgs
  14. where
  15. mainWithArgs : List String -> IO Unit
  16. mainWithArgs [] = putStrLn "Give a file name silly"
  17. mainWithArgs (file :: []) =
  18. runFileIO (
  19. openFile file readMode >>= \h ->
  20. -- hGetLine h hd >>= \s ->
  21. -- hClose h hd >>= \_ ->
  22. hGetContents h hd >>= \s ->
  23. return s
  24. ) `bindIO` \s -> putStrLn s
  25. mainWithArgs (_ :: _ :: _) =
  26. putStrLn "Just one file will do, thank you very much."