Skip to content

Instantly share code, notes, and snippets.

@abdulsattar
Created October 15, 2016 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdulsattar/bb2f9ba2e701231f688afdf6d811ada8 to your computer and use it in GitHub Desktop.
Save abdulsattar/bb2f9ba2e701231f688afdf6d811ada8 to your computer and use it in GitHub Desktop.
import Effects
import Effect.File
import Effect.StdIO
import Control.IOExcept
readFile : Eff (FileOpResult (List String)) [FILE R]
readFile = readAcc [] where
readAcc : List String -> Eff (FileOpResult (List String)) [FILE R]
readAcc acc = if (not !eof)
then do
(Result str) <- readLine
readAcc (str::acc)
else pure $ Result (reverse acc)
dumpFile : String -> Eff () [FILE (), STDIO]
dumpFile name = do
Success <- open name Read
| (FError _) => do putStrLn "Error!"
(Result fcontents) <- readFile
| (FError _) => do close
putStrLn "Error!"
putStrLn (show fcontents)
close
main : IO ()
main = run (dumpFile "input.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment