Skip to content

Commit 9b00848

Browse files
author
Rizo Isrof
committed
merge
2 parents 784a045 + f0aec62 commit 9b00848

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

Modules.fold

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,104 @@ mod List
5050

5151
end
5252

53+
--
54+
-- # Modules
55+
--
56+
-- * 1.0 Definition
57+
-- * 2.0 Loading and Opening Modules
58+
-- * 3.0 Functors
59+
60+
--
61+
-- ## 2.0 Loading and Opening Modules
62+
--
63+
64+
--
65+
-- Load a module
66+
--
67+
-> load OS
68+
69+
-- Only the module can be used
70+
-> user = OS.getenv "USER"
71+
user :: String = "dmr"
72+
73+
74+
--
75+
-- Load a module using an alias
76+
--
77+
-> load OS as POSIX
78+
79+
-- Only the alias can be used
80+
-> user = POSIX.getenv "USER"
81+
user :: String = "dmr"
82+
83+
-- Using module name directly will not work
84+
-> user = OS.getenv "USER"
85+
* Error: Unbound module OS
86+
87+
88+
--
89+
-- Load multiple modules
90+
--
91+
-> load OS, Sys
92+
93+
-- Both modules can be used.
94+
-> user = OS.getenv "USER"
95+
user :: String = "dmr"
96+
-> Sys.time ()
97+
:: Float = 0.276656
98+
99+
100+
--
101+
-- Load a module and some symbols.
102+
--
103+
-> load OS with: [getenv, getuid as uid]
104+
105+
-- The `getenv` and `getuid` symbols can be used directly.
106+
-> user, uid = getenv "USER", uid ()
107+
user :: String = "dmr"
108+
uid :: Int = 501
109+
-- The `OS` was also loaded and can be used.
110+
-> OS.getguid ()
111+
:: Int = 20
112+
113+
--
114+
-- Open all module symbols
115+
--
116+
-- The usage of `open` without selection is discouraged since conflicting
117+
-- symbols may be introduced in the scope. In which case, for a conflicting
118+
-- name, the last imported definition will be used.
119+
--
120+
-> open OS
121+
122+
-- All module symbols can be used directly.
123+
-> getuid ()
124+
:: Int = 501
125+
-> getgid ()
126+
:: Int = 20
127+
-- Opened modules are not loaded.
128+
-> OS.getuid ()
129+
* Error Unbound module OS
130+
131+
132+
--
133+
-- Open only some module symbols
134+
--
135+
-> open OS only: [getcwd as cwd]
136+
137+
-- Only the symbols `cwd` was opened from the module.
138+
-> cwd ()
139+
:: String = "/home/dmr"
140+
141+
-- Open all module symbols with exceptions
142+
open OS hide: [mkdir, mkfifo]
143+
144+
145+
146+
--
147+
-- Interfaces
148+
--
149+
>>>>>>> f0aec6245a6953af18342ce828fcf1e85d19c5b8
150+
53151
protocol Animal T {
54152
init :: String -> T
55153
name :: T -> String

0 commit comments

Comments
 (0)