std.io

Modules

std.io.read Functions and types for working with Readers.
std.io.write Functions and types for working with Writers.

Functions for working with I/O

Types

type File = File

type OpenOptions = 
    | Read
    | Write
    | Append
    | Truncate
    | Create
    | CreateNew

type IO a = <opaque>

Values

let open_file path : String -> IO File

Opens the file at path in read-only mode. Fails if the file does not exist.

let create_file path : String -> IO File

Opens a file in write-only mode. If the file already exists, it will be truncated. If the file does not exist, it will be created.

let functor : Functor IO

A Functor represents an action on a parameterized type which does not change the structure with the mapped type.

The following laws should hold:

  • map id == id
  • map (f << g) == map f << map g

let applicative : Applicative IO

A Functor with application.

The following laws should hold:

  • wrap id <*> v = v
  • wrap (<<) <> u <> v <> w = u <> (v <*> w)
  • wrap f <*> wrap x = wrap (f x)
  • u <> wrap y = wrap (\g -> g x) <> u

let monad : Monad IO

A generalised interface for imperatively sequencing actions

let read : Read File

Allows reading bytes from a. Generally, reading from a reader advances its internal cursor. This means that multiple read calls with the same arguments usually do not return the same value.

let write : Write File

Allows writing bytes to a sink. To ensure that all data has been written, writes have to be paired with a flush.

let disposable : Disposable File

A resource that has to be released after use, for example a file handle or a database connection.

let flat_map : forall b a . (a -> IO b) -> IO a -> IO b

let wrap : forall a . a -> IO a

let open_file_with : String -> Array (| Read
            | Write
            | Append
            | Truncate
            | Create
            | CreateNew) -> IO File

let read_file_to_string : String -> IO String

let read_file_to_array : String -> IO (Array Byte)

let read_file : File -> Int -> IO (Option (Array Byte))

let read_file_to_end : File -> IO (Array Byte)

let write_slice_file : File -> Array Byte -> Int -> Int -> IO Int

let flush_file : File -> IO ()

let close_file : File -> IO ()

let is_file_closed : File -> Bool

let read_char : IO Char

let read_line : IO String

let print : String -> IO ()

let println : String -> IO ()

let flush_stdout : IO ()

let eprint : String -> IO ()

let eprintln : String -> IO ()

let catch : forall a . IO a -> (String -> IO a) -> IO a

let throw : forall a . String -> IO a

let run_expr : String -> IO { value : String, typ : String }

let load_script : String -> String -> IO String

let default_buf_len : Int