69 lines · 1.9 KB · Text
RawDownload
module Control.App.FileIO import Control.App import Data.Listimport Data.Stringsimport System.File toFileEx : FileError -> FileExtoFileEx (GenericFileError i) = GenericFileEx itoFileEx FileReadError = FileReadErrortoFileEx FileWriteError = FileWriteErrortoFileEx FileNotFound = FileNotFoundtoFileEx PermissionDenied = PermissionDeniedtoFileEx FileExists = FileExists public exportinterface Has [Exception IOError] e => FileIO e where  withFile : String -> Mode ->              (onError : IOError -> App e a) ->             (onOpen : File -> App e a) ->              App e a  fGetStr : File -> App e String  fPutStr : File -> String -> App e ()  fEOF : File -> App e Bool -- TODO : Add Binary File IO with buffers exportreadFile : FileIO e => String -> App e StringreadFile f    = withFile f Read throw $ \h =>        do content <- read [] h           pure (fastAppend content)  where    read : List String -> File -> App e (List String)    read acc h        = do eof <- FileIO.fEOF h             if eof                then pure (reverse acc)                else do str <- fGetStr h                        read (str :: acc) h exportHas [PrimIO, Exception IOError] e => FileIO e where  withFile fname m onError proc      = do Right h <- primIO $ openFile fname m              | Left err => onError (FileErr (toFileEx err))           res <- catch (proc h) onError           pure res   fGetStr f      = do Right str <- primIO $ fGetLine f              | Left err => throw (FileErr (toFileEx err))           pure str   fPutStr f str      = do Right () <- primIO $ File.fPutStr f str               | Left err => throw (FileErr (toFileEx err))           pure ()   fEOF f = primIO $ fEOF f exportwithFileIO : Has [PrimIO] e =>             App (IOError :: e) a ->             (ok : a -> App e b) ->             (err : IOError -> App e b) -> App e bwithFileIO prog ok err = handle prog ok err

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t