Advertisement
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> }
- static new :: () -> (f::File, Closed f)
- open :: Path -> Either (f::File, Closed f, Error) (f::File, Opened f)
- read :: Opened this -> int -> Either (f::File , Closed f, Error) (f::File, Opened f, Bytes)
- write :: Opened this -> Bytes -> Either (f::File, Closed f, Error) (f::File, Opened f)
- close :: Opened this -> (f::File, Closed f)
- File.new () =
- let
- f = file { InvalidHandle }
- in
- (f, c_closed f)
- File.open this 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement