Skip to content

Instantly share code, notes, and snippets.

@sungkmi
Last active December 30, 2016 15:20
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 sungkmi/3703ea08bf1b2c44ea0a29b663d56d38 to your computer and use it in GitHub Desktop.
Save sungkmi/3703ea08bf1b2c44ea0a29b663d56d38 to your computer and use it in GitHub Desktop.
import Data.Vect
readToBlank : IO (List String)
readToBlank = do x <- getLine
if (x == "")
then pure []
else do xs <- readToBlank
pure (x :: xs)
readAndSave : IO ()
readAndSave = do xs <- readToBlank
filename <- getLine
Right h <- writeFile filename (unlines xs)
| Left err => putStrLn (show err)
pure ()
readVectFile : (filename : String) -> IO (n ** Vect n String)
readVectFile filename =
do
Right h <- openFile filename Read
| Left err => pure (_ ** [])
lines <- readFileLines h
pure lines
where
readFileLines: (h: File) -> IO (n ** Vect n String)
readFileLines h =
do isEnd <- fEOF h
if (isEnd)
then do closeFile h
pure (_ ** [])
else do Right line <- fGetLine h
| Left err => pure (_ ** [])
(_ ** lines) <- readFileLines h
pure (_ ** line :: lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment