Skip to content

Commit f0aec62

Browse files
authored
Update Modules.fold
1 parent 8551355 commit f0aec62

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

Modules.fold

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,97 @@
11

2+
--
3+
-- # Modules
4+
--
5+
-- * 1.0 Definition
6+
-- * 2.0 Loading and Opening Modules
7+
-- * 3.0 Functors
8+
9+
--
10+
-- ## 2.0 Loading and Opening Modules
11+
--
12+
13+
--
14+
-- Load a module
15+
--
16+
-> load OS
17+
18+
-- Only the module can be used
19+
-> user = OS.getenv "USER"
20+
user :: String = "dmr"
21+
22+
23+
--
24+
-- Load a module using an alias
25+
--
26+
-> load OS as POSIX
27+
28+
-- Only the alias can be used
29+
-> user = POSIX.getenv "USER"
30+
user :: String = "dmr"
31+
32+
-- Using module name directly will not work
33+
-> user = OS.getenv "USER"
34+
* Error: Unbound module OS
35+
36+
37+
--
38+
-- Load multiple modules
39+
--
40+
-> load OS, Sys
41+
42+
-- Both modules can be used.
43+
-> user = OS.getenv "USER"
44+
user :: String = "dmr"
45+
-> Sys.time ()
46+
:: Float = 0.276656
47+
48+
49+
--
50+
-- Load a module and some symbols.
51+
--
52+
-> load OS with: [getenv, getuid as uid]
53+
54+
-- The `getenv` and `getuid` symbols can be used directly.
55+
-> user, uid = getenv "USER", uid ()
56+
user :: String = "dmr"
57+
uid :: Int = 501
58+
-- The `OS` was also loaded and can be used.
59+
-> OS.getguid ()
60+
:: Int = 20
61+
62+
--
63+
-- Open all module symbols
64+
--
65+
-- The usage of `open` without selection is discouraged since conflicting
66+
-- symbols may be introduced in the scope. In which case, for a conflicting
67+
-- name, the last imported definition will be used.
68+
--
69+
-> open OS
70+
71+
-- All module symbols can be used directly.
72+
-> getuid ()
73+
:: Int = 501
74+
-> getgid ()
75+
:: Int = 20
76+
-- Opened modules are not loaded.
77+
-> OS.getuid ()
78+
* Error Unbound module OS
79+
80+
81+
--
82+
-- Open only some module symbols
83+
--
84+
-> open OS only: [getcwd as cwd]
85+
86+
-- Only the symbols `cwd` was opened from the module.
87+
-> cwd ()
88+
:: String = "/home/dmr"
89+
90+
-- Open all module symbols with exceptions
91+
open OS hide: [mkdir, mkfifo]
92+
93+
94+
295
--
396
-- Interfaces
497
--

0 commit comments

Comments
 (0)