-
Notifications
You must be signed in to change notification settings - Fork 1
/
IO.milone
31 lines (27 loc) · 882 Bytes
/
IO.milone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Provides the IO mechanism.
// IO = input/output.
// Here IO indicates a kind of operations that affect the host environment (OS)
// such as file system, network, processes etc.
open Std.Own
open Std.StdError
/// Owned marker to make it explicit for a function to use IO operations.
///
/// As a convention, functions that use IO should take an IO value and return it.
/// By passing an IO value around, dependencies are explicitly expressed
/// between use of IO-dependent functions.
type IO = private IO of Own<unit>
module IO =
/// Executes a program that uses IO operations inside of it.
//
// Usage:
//
// ```fs
// open Std.StdError
//
// let main _ = never (IO.exec (fun io -> action io))
// ```
let exec (action: IO -> IO) : never =
let (IO io) = action (IO(Own.acquire ()))
Own.release io
__nativeStmt "exit(0);"
unreachable ()