Created
November 7, 2018 09:54
-
-
Save zindel/54ac6b9e920643aafe7f96c035d1aa9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Action : sig | |
| type _ t | |
| val execute : 'a t -> 'a | |
| val readFile : string -> string t | |
| val writeFile : string -> string -> unit t | |
| end = struct | |
| type _ t = | |
| | ReadFile : string -> string t | |
| | WriteFile : string * string -> unit t | |
| let readFile f = ReadFile f | |
| let writeFile f data = WriteFile (f, data) | |
| let execute : type res. res t -> res = function | |
| | ReadFile f -> | |
| let ic = open_in f in | |
| let rec read acc = | |
| try | |
| let acc = input_line ic :: acc in | |
| read acc | |
| with End_of_file -> acc | |
| in | |
| let data = read [] in | |
| close_in ic ; String.concat "\n" data | |
| | WriteFile (f, data) -> | |
| let oc = open_out f in | |
| Printf.fprintf oc "%s\n" data ; | |
| close_out oc | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment