-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExIO.hs
162 lines (112 loc) · 3.21 KB
/
ExIO.hs
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
module ExIO where
import Prelude hiding
( putStr
, putStrLn
, getLine
, interact
, (>>)
, (>>=)
)
-- read through the whole module first, to get an idea
-- of what's required and to decide where to start
getLine :: IO String
getLine = undefined
getInt :: IO Int
getInt = undefined
getSafeInt :: IO (Maybe Int)
getSafeInt = undefined
-- sequencing: first do f ignoring its result, then do g and keep its result
infixl 1 >>
(>>) :: IO a -> IO b -> IO b
ax >> ay = undefined
-- pauses till the user presses any normal key
pause :: IO ()
pause = undefined
skip :: IO ()
skip = undefined
newline :: IO ()
newline = undefined
-- define it as a foldr
putStr :: String -> IO ()
putStr = undefined
-- transform f into one "just like f" except that it prints a newline
-- after any side-effects f may had
lnize :: (a -> IO b) -> a -> IO b
lnize f = undefined
putStrLn :: String -> IO ()
putStrLn = lnize putStr
putCharLn :: Char -> IO ()
putCharLn = lnize putChar
-- reads the entire user input as a single string, transforms it, and prints it
interact :: (String -> String) -> IO ()
interact f = do
x <- getLine
putStr (f x)
perlineize :: (String -> String) -> (String -> String)
perlineize f = unlines . map f . lines
interactPerLine :: (String -> String) -> IO ()
interactPerLine = interact . perlineize
when :: Bool -> IO () -> IO ()
when = undefined
unless :: Bool -> IO () -> IO ()
unless = undefined
guard :: Bool -> IO ()
guard = undefined
forever :: IO a -> IO b
forever = undefined
-- transforms the action given to an equivalent one that has no result
void :: IO a -> IO ()
void = undefined
-- Kleisli compositions
infixr 1 >=>, <=<
-- diagrammatic order
(>=>) :: (a -> IO b) -> (b -> IO c) -> (a -> IO c)
f >=> g = undefined
-- traditional order
-- comparison of types:
-- (.) :: (b -> c) -> (a -> b) -> a -> c
-- (<=<) :: (b -> IO c) -> (a -> IO b) -> a -> IO c
(<=<) :: (b -> IO c) -> (a -> IO b) -> (a -> IO c)
(<=<) = flip (>=>)
-- Bind
infixl 1 >>=
(>>=) :: IO a -> (a -> IO b) -> IO b
ax >>= f = undefined
infixl 4 $>, <$
-- make an action that has the side effects of the action on the left
-- but with result the value on the right
($>) :: IO a -> b -> IO b
ax $> y = undefined
-- vice-versa
(<$) :: a -> IO b -> IO a
x <$ ioy = undefined
ap :: IO (a -> b) -> IO a -> IO b
af `ap` ax = undefined
filterIO :: (a -> IO Bool) -> [a] -> IO [a]
filterIO = undefined
iomap :: (a -> b) -> IO a -> IO b
iomap = undefined
mapIO :: (a -> IO b) -> [a] -> IO [b]
mapIO = undefined
zipWithIO :: (a -> b -> IO c) -> [a] -> [b] -> IO [c]
zipWithIO = undefined
zipWithIO_ :: (a -> b -> IO c) -> [a] -> [b] -> IO ()
zipWithIO_ = undefined
sequenceIO :: [IO a] -> IO [a]
sequenceIO = undefined
sequenceIO_ :: [IO a] -> IO ()
sequenceIO_ = undefined
replicateIO :: Integral i => i -> IO a -> IO [a]
replicateIO = undefined
replicateIO_ :: Integral i => i -> IO a -> IO [a]
replicateIO_ = undefined
forIO :: [a] -> (a -> IO b) -> IO [b]
forIO = undefined
forIO_ :: [a] -> (a -> IO b) -> IO ()
forIO_ = undefined
joinIO :: IO (IO a) -> IO a
joinIO = undefined
foldlIO :: (b -> a -> IO b) -> b -> [a] -> IO b
foldlIO = undefined
foldlIO_ :: (b -> a -> IO b) -> b -> [a] -> IO ()
foldlIO_ = undefined