Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- linear type File
- { handle : i32 }
- --a private type, "evidence" for file state
- adt Opened<File f>{ c_opened :: Opened<f> }
- adt Closed<File f>{ c_closed :: Closed<f> }
- new :: () -> (f::File, Closed f)
- open :: (this::File) -> Closed this -> Path -> Either (f::File, Closed f, Error) (f::File, Opened f)
- read :: (this::File) -> Opened this -> int -> Either (f::File , Closed f, Error) (f::File, Opened f, Bytes)
- write :: (this::File) -> Opened this -> Bytes -> Either (f::File, Closed f, Error) (f::File, Opened f)
- close :: (this::File) -> Opened this -> (f::File, Closed f)
- File.new () =
- let
- f = file { InvalidHandle }
- in
- (f, c_closed f)
- File.open this ev_closed path =
- let h = fopen(path, "rw")
- in if h == 0
- then let f = File{h} in (Left f, c_closed f, "can't open the file")
- else (Right f, c_opened f)
Add Comment
Please, Sign In to add comment