Skip to content

Instantly share code, notes, and snippets.

@waynejo
Created December 30, 2016 13:05
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 waynejo/dc493bac88a16b2d5b4d59e4df9f2e4b to your computer and use it in GitHub Desktop.
Save waynejo/dc493bac88a16b2d5b4d59e4df9f2e4b to your computer and use it in GitHub Desktop.
foldLString : (List String) -> String
foldLString [] = ""
foldLString (x :: xs) = x ++ "\n" ++ foldLString xs
readAndSave : IO ()
readAndSave = do lines <- readToBlank
putStrLn "Enter file name:"
fileName <- getLine
writeFile fileName (foldLString lines)
pure ()
subReadVectFile : (handle : File) -> IO (n ** Vect n String)
subReadVectFile handle = do Right x <- fGetLine handle
| Left err => pure (_ ** [])
isEnd <- fEOF handle
if (isEnd)
then pure (_ ** [])
else do (_ ** xs) <- subReadVectFile handle
pure(_ ** x :: xs)
readVectFile : (filename : String) -> IO (n ** Vect n String)
readVectFile filename = do Right h <- openFile filename Read
| Left err => pure (_ ** [])
result <- subReadVectFile h
closeFile h
pure(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment