-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandard.txt
207 lines (156 loc) · 2.03 KB
/
standard.txt
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
*Numbers
=3 + 2
=3 - 2
=3 * 2
=3 / 2
=3 ^ 2
=3 ** 2.5
div 3 2
mod 3 2
m
max 3 4
min 3 4
abs (-3)
odd 3
even 3
gcd 4 6
lcm 4 6
floor 3.6
round 3.6
ceiling 3.6
sum [1..5]
product [1..5]
maximum [1,3,2]
minimum [1,3,2]
pi
sqrt 2
sin 0.4
cos 0.4
m
*Booleans
=3 > 2
=3 >= 2
=3 < 2
=3 <= 2
=3 == 2
=3 /= 2
=True && False
=True || False
not True
and [False, False, True]
or [False, False, True]
*Constructing Lists
='h' : "ello"
="he" ++ "llo"
replicate 3 'a'
concat ["he", "ll", "o"]
m
intersperse ',' "abc"
intercalate "--" ["one", "two"]
*Querying Lists
null "abc"
length "abc"
elem e "hello"
find odd [2,4,5,6]
m
--lookup 4 [(3, "hey"), (4, "ho")]
isPrefixOf "he" "hello"
m
FindIndex odd [2,3,5]
FindIndices odd [2,3,5]
t
*Extracting from Lists
="hello" !! 4
head "abc"
tail "abc"
init "abc"
last "abc"
take 2 "hello"
drop 2 "hello"
takeWhile odd [1,3,2]
dropWhile odd [1,3,2]
stripPrefix "he" "hello"
*Splitting Lists
splitAt 2 "hello"
span odd [1,3,4]
break even [1,3,4]
partition odd [1,2,3,4]
*Infinite lists
iterate (+1) 0
repeat 'a'
cycle "hello"
*Lists as sets
nub "mississippi"
delete 'e' "hello"
="ab" \\ "ac"
union "ab" "ac"
m
*Sorting
sort [3,4,2]
m
insert 3 [1,2,4]
m
compare 3 4
*Misc Lists
zip [1..] "hello"
zipWith (+) [1,2,3] [4,5,6]
m
unzip [(4,'a'),(5,'z')]
m
reverse "hi"
transpose ["abc", "123"]
subsequences "abc"
permutations "abc"
group "hello"
inits "abc"
tails "abc"
t
*Strings
lines "one\ntwo\n"
unlines ["one", "two"]
words "one two"
unwords ["one", "two"]
show 3
read "3"
*Characters
toUpper 'a'
toLower 'A'
digitToInt '5'
intToDigit 5
ord 'A'
chr 65
isNumber '4'
isLetter 'a'
m
*Higher order
map sqrt [1..5]
filter odd [1..5]
all odd [2,3,4]
any odd [2,3,4]
=sqrt . sqrt
=sqrt $ 4
flip take
foldr (+) 0 [1..5]
foldl' (+) 0 [1..5]
m
scanr (+) 0 [1..5]
scanl' (+) 0 [1..5]
m
*I/O
main
interact $ map toUpper
putChar 'a'
putStr "hi"
putStrLn "hi"
print 4
getchar
getLine
getContents
readFile "a.txt"
writeFile "a.txt" "hello"
appendFile "a.txt" "hello"
*Misc
fst (3,"hi")
snd (3,"hi")
id 3
const 3 "hi"