-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhaskellcheatsheet.html
321 lines (312 loc) · 151 KB
/
haskellcheatsheet.html
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<!doctype html>
<html>
<head>
<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>
<title>haskellcheatsheet.md</title><link href='https://fonts.googleapis.com/css?family=Merriweather:900,900italic,300,300italic&subset=latin-ext' rel='stylesheet' type='text/css' />
<link href='https://fonts.googleapis.com/css?family=Lato:900,300&subset=latin-ext' rel='stylesheet' type='text/css' /><style type='text/css'>html {overflow-x: initial !important;}#write, body { height: auto; }
#write, #write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write ol, #write p, #write ul { position: relative; }
#write, #write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p, #write pre { width: inherit; }
#write, pre { white-space: pre-wrap; }
.CodeMirror, .md-fences, table { text-align: left; }
.md-reset, a:active, a:hover { outline: 0px; }
.md-reset, .md-toc-item a { text-decoration: none; }
.MathJax_SVG, .md-reset { float: none; direction: ltr; }
:root { --bg-color:#ffffff; --text-color:#333333; }
html { font-size: 14px; background-color: var(--bg-color); color: var(--text-color); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
body { margin: 0px; padding: 0px; bottom: 0px; top: 0px; left: 0px; right: 0px; font-size: 1rem; line-height: 1.42857; overflow-x: hidden; background: inherit; }
.in-text-selection, ::selection { background: rgb(181, 214, 252); text-shadow: none; }
#write { margin: 0px auto; word-break: normal; word-wrap: break-word; padding-bottom: 70px; overflow-x: visible; }
.first-line-indent #write p .md-line { text-indent: 0px; }
.first-line-indent #write li, .first-line-indent #write p, .first-line-indent #write p .md-line:first-child { text-indent: 2em; }
.for-image #write { padding-left: 8px; padding-right: 8px; }
body.typora-export { padding-left: 30px; padding-right: 30px; }
@media screen and (max-width: 500px) {
body.typora-export { padding-left: 0px; padding-right: 0px; }
.CodeMirror-sizer { margin-left: 0px !important; }
.CodeMirror-gutters { display: none !important; }
}
#write > blockquote:first-child, #write > div:first-child, #write > ol:first-child, #write > p:first-child, #write > pre:first-child, #write > table:first-child, #write > ul:first-child { margin-top: 30px; }
#write li > table:first-child { margin-top: -20px; }
img { max-width: 100%; vertical-align: middle; }
button, input, select, textarea { color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; }
input[type="checkbox"], input[type="radio"] { line-height: normal; padding: 0px; }
*, ::after, ::before { box-sizing: border-box; }
h1 { font-size: 2rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.6rem; }
h4 { font-size: 1.4rem; }
h5 { font-size: 1.2rem; }
h6 { font-size: 1rem; }
p { -webkit-margin-before: 1rem; -webkit-margin-after: 1rem; -webkit-margin-start: 0px; -webkit-margin-end: 0px; }
.mathjax-block { margin-top: 0px; margin-bottom: 0px; -webkit-margin-before: 0px; -webkit-margin-after: 0px; }
.hidden { display: none; }
.md-blockmeta { color: rgb(204, 204, 204); font-weight: 700; font-style: italic; }
a { cursor: pointer; }
sup.md-footnote { padding: 2px 4px; background-color: rgba(238, 238, 238, 0.7); color: rgb(85, 85, 85); border-radius: 4px; }
#write input[type="checkbox"] { cursor: pointer; width: inherit; height: inherit; }
#write > figure:first-child { margin-top: 16px; }
figure { overflow-x: auto; margin: -8px 0px 0px -8px; max-width: calc(100% + 16px); padding: 8px; }
tr { break-inside: avoid; break-after: auto; }
thead { display: table-header-group; }
table { border-collapse: collapse; border-spacing: 0px; width: 100%; overflow: auto; break-inside: auto; }
.CodeMirror-line, .md-fences { break-inside: avoid; }
table.md-table td { min-width: 80px; }
.CodeMirror-gutters { border-right: 0px; background-color: inherit; margin-right: 4px; }
.CodeMirror-placeholder { opacity: 0.3; }
.CodeMirror pre { padding: 0px 4px; }
.CodeMirror-lines { padding: 0px; }
div.hr:focus { cursor: none; }
.md-fences { font-size: 0.9rem; display: block; overflow: visible; white-space: pre; background: inherit; position: relative !important; }
.md-diagram-panel { width: 100%; margin-top: 10px; text-align: center; padding-top: 0px; padding-bottom: 8px; overflow-x: auto; }
.md-fences .CodeMirror.CodeMirror-wrap { top: -1.6em; margin-bottom: -1.6em; }
.md-fences.mock-cm { white-space: pre-wrap; }
.show-fences-line-number .md-fences { padding-left: 0px; }
.show-fences-line-number .md-fences.mock-cm { padding-left: 40px; }
.footnotes { opacity: 0.8; font-size: 0.9rem; margin-top: 1em; margin-bottom: 1em; }
.footnotes + .footnotes { margin-top: 0px; }
.md-reset { margin: 0px; padding: 0px; border: 0px; vertical-align: top; background: 0px 0px; text-shadow: none; position: static; width: auto; height: auto; white-space: nowrap; cursor: inherit; -webkit-tap-highlight-color: transparent; line-height: normal; font-weight: 400; text-align: left; box-sizing: content-box; }
.md-toc-inner, a img, img a { cursor: pointer; }
li div { padding-top: 0px; }
blockquote { margin: 1rem 0px; }
li .mathjax-block, li p { margin: 0.5rem 0px; }
li { margin: 0px; position: relative; }
blockquote > :last-child { margin-bottom: 0px; }
blockquote > :first-child { margin-top: 0px; }
.footnotes-area { color: rgb(136, 136, 136); margin-top: 0.714rem; padding-bottom: 0.143rem; white-space: nowrap; }
@media print {
body, html { border: 1px solid transparent; height: 99%; break-after: avoid; break-before: avoid; }
#write { margin-top: 0px; border-color: transparent !important; }
.typora-export * { -webkit-print-color-adjust: exact; }
h1, h2, h3, h4, h5, h6 { break-after: avoid-page; orphans: 2; }
p { orphans: 4; }
html.blink-to-pdf { font-size: 13px; }
.typora-export #write { padding-left: 1cm; padding-right: 1cm; padding-bottom: 0px; break-after: avoid; }
.typora-export #write::after { height: 0px; }
@page { margin: 20mm 0px; }
}
.footnote-line { margin-top: 0.714em; font-size: 0.7em; }
pre.md-meta-block { font-size: 0.8rem; min-height: 0.8rem; white-space: pre-wrap; background: rgb(204, 204, 204); display: block; overflow-x: hidden; }
p > img:only-child { display: block; margin: auto; }
.md-line > .md-image:only-child, p > .md-image:only-child { display: inline-block; width: 100%; text-align: center; }
.mathjax-block:not(:empty)::after, .md-toc-content::after, .md-toc::after { display: none; }
#write .MathJax_Display { margin: 0.8em 0px 0px; }
.mathjax-block { white-space: pre; overflow: hidden; width: 100%; }
p + .mathjax-block { margin-top: -1.143rem; }
[contenteditable="true"]:active, [contenteditable="true"]:focus { outline: 0px; box-shadow: none; }
.md-task-list-item { position: relative; list-style-type: none; }
.task-list-item.md-task-list-item { padding-left: 0px; }
.md-task-list-item > input { position: absolute; top: 0px; left: 0px; margin-left: -1.2em; margin-top: calc(1em - 10px); }
.math { font-size: 1rem; }
.md-toc { min-height: 3.58rem; position: relative; font-size: 0.9rem; border-radius: 10px; }
.MathJax_SVG, .mathjax-block .MathJax_SVG_Display { text-indent: 0px; max-width: none; max-height: none; min-height: 0px; }
.md-toc-content { position: relative; margin-left: 0px; }
.md-toc-item { display: block; color: rgb(65, 131, 196); }
.md-toc-inner:hover { }
.md-toc-inner { display: inline-block; }
.md-toc-h1 .md-toc-inner { margin-left: 0px; font-weight: 700; }
.md-toc-h2 .md-toc-inner { margin-left: 2em; }
.md-toc-h3 .md-toc-inner { margin-left: 4em; }
.md-toc-h4 .md-toc-inner { margin-left: 6em; }
.md-toc-h5 .md-toc-inner { margin-left: 8em; }
.md-toc-h6 .md-toc-inner { margin-left: 10em; }
@media screen and (max-width: 48em) {
.md-toc-h3 .md-toc-inner { margin-left: 3.5em; }
.md-toc-h4 .md-toc-inner { margin-left: 5em; }
.md-toc-h5 .md-toc-inner { margin-left: 6.5em; }
.md-toc-h6 .md-toc-inner { margin-left: 8em; }
}
a.md-toc-inner { font-size: inherit; font-style: inherit; font-weight: inherit; line-height: inherit; }
.footnote-line a:not(.reversefootnote) { color: inherit; }
.md-attr { display: none; }
.md-fn-count::after { content: "."; }
code, pre, tt { font-family: var(--monospace); }
.md-comment { color: rgb(162, 127, 3); opacity: 0.8; font-family: var(--monospace); }
code { text-align: left; }
a.md-print-anchor { border-width: initial !important; border-style: none !important; border-color: initial !important; display: inline-block !important; position: absolute !important; width: 1px !important; right: 0px !important; outline: 0px !important; background: 0px 0px !important; text-decoration: initial !important; text-shadow: initial !important; }
.md-inline-math .MathJax_SVG .noError { display: none !important; }
.mathjax-block .MathJax_SVG_Display { text-align: center; margin: 1em 0px; position: relative; min-width: 100%; width: auto; display: block !important; }
.MathJax_SVG_Display, .md-inline-math .MathJax_SVG_Display { width: auto; margin: inherit; display: inline-block !important; }
.MathJax_SVG .MJX-monospace { font-family: monospace; }
.MathJax_SVG .MJX-sans-serif { font-family: sans-serif; }
.MathJax_SVG { display: inline; font-style: normal; font-weight: 400; line-height: normal; zoom: 90%; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; min-width: 0px; border: 0px; padding: 0px; margin: 0px; }
.MathJax_SVG * { transition: none; }
.os-windows.monocolor-emoji .md-emoji { font-family: "Segoe UI Symbol", sans-serif; }
.md-diagram-panel > svg, [lang="flow"] svg, [lang="mermaid"] svg { max-width: 100%; }
[lang="mermaid"] .node text { font-size: 1rem; }
table tr th { border-bottom: 0px; }
.CodeMirror, .CodeMirror-sizer { position: relative; }
.CodeMirror.cm-s-inner { background: inherit; }
.fences-no-line-wrapping .md-fences .CodeMirror { margin-top: -30px; }
.CodeMirror-scroll { overflow-y: hidden; overflow-x: auto; }
.CodeMirror-lines { padding: 4px 0px; }
.CodeMirror-gutter-filler, .CodeMirror-scrollbar-filler { background-color: rgb(255, 255, 255); }
.CodeMirror-scroll, .cm-s-inner .CodeMirror-activeline-background { background: inherit; }
.CodeMirror-linenumber { padding: 0px 3px 0px 5px; text-align: right; color: rgb(153, 153, 153); }
.cm-s-inner .cm-keyword { color: rgb(119, 0, 136); }
.cm-s-inner .cm-atom, .cm-s-inner.cm-atom { color: rgb(34, 17, 153); }
.cm-s-inner .cm-number { color: rgb(17, 102, 68); }
.cm-s-inner .cm-def { color: rgb(0, 0, 255); }
.cm-s-inner .cm-variable { color: rgb(0, 0, 0); }
.cm-s-inner .cm-variable-2 { color: rgb(0, 85, 170); }
.cm-s-inner .cm-variable-3 { color: rgb(0, 136, 85); }
.cm-s-inner .cm-string { color: rgb(170, 17, 17); }
.cm-s-inner .cm-property { color: rgb(0, 0, 0); }
.cm-s-inner .cm-operator { color: rgb(152, 26, 26); }
.cm-s-inner .cm-comment, .cm-s-inner.cm-comment { color: rgb(170, 85, 0); }
.cm-s-inner .cm-string-2 { color: rgb(255, 85, 0); }
.cm-s-inner .cm-meta, .cm-s-inner .cm-qualifier { color: rgb(85, 85, 85); }
.cm-s-inner .cm-builtin { color: rgb(51, 0, 170); }
.cm-s-inner .cm-bracket { color: rgb(153, 153, 119); }
.cm-s-inner .cm-tag { color: rgb(17, 119, 0); }
.cm-s-inner .cm-attribute { color: rgb(0, 0, 204); }
.cm-s-inner .cm-header, .cm-s-inner.cm-header { color: rgb(0, 0, 255); }
.cm-s-inner .cm-quote, .cm-s-inner.cm-quote { color: rgb(0, 153, 0); }
.cm-s-inner .cm-hr, .cm-s-inner.cm-hr { color: rgb(153, 153, 153); }
.cm-s-inner .cm-link, .cm-s-inner.cm-link { color: rgb(0, 0, 204); }
.cm-negative { color: rgb(221, 68, 68); }
.cm-positive { color: rgb(34, 153, 34); }
.cm-header, .cm-strong { font-weight: 700; }
.cm-del { text-decoration: line-through; }
.cm-em { font-style: italic; }
.cm-link { text-decoration: underline; }
.cm-error, .cm-invalidchar { color: red; }
.cm-constant { color: rgb(38, 139, 210); }
.cm-defined { color: rgb(181, 137, 0); }
div.CodeMirror span.CodeMirror-matchingbracket { color: rgb(0, 255, 0); }
div.CodeMirror span.CodeMirror-nonmatchingbracket { color: rgb(255, 34, 34); }
.CodeMirror { height: auto; overflow: hidden; }
.CodeMirror-scroll { margin-bottom: -30px; padding-bottom: 30px; height: 100%; outline: 0px; position: relative; box-sizing: content-box; }
.CodeMirror-gutter-filler, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-vscrollbar { position: absolute; z-index: 6; display: none; }
.CodeMirror-vscrollbar { right: 0px; top: 0px; overflow-x: hidden; overflow-y: scroll; }
.CodeMirror-hscrollbar { bottom: 0px; left: 0px; overflow-y: hidden; overflow-x: scroll; }
.CodeMirror-scrollbar-filler { right: 0px; bottom: 0px; }
.CodeMirror-gutter-filler { left: 0px; bottom: 0px; }
.CodeMirror-gutters { border-right: 1px solid rgb(221, 221, 221); background: inherit; white-space: nowrap; position: absolute; left: 0px; top: 0px; padding-bottom: 30px; z-index: 3; }
.CodeMirror-gutter { white-space: normal; height: 100%; box-sizing: content-box; padding-bottom: 30px; margin-bottom: -32px; display: inline-block; }
.CodeMirror-gutter-wrapper { position: absolute; z-index: 4; background: 0px 0px !important; border: none !important; }
.CodeMirror-gutter-background { position: absolute; top: 0px; bottom: 0px; z-index: 4; }
.CodeMirror-gutter-elt { position: absolute; cursor: default; z-index: 4; }
.CodeMirror-lines { cursor: text; }
.CodeMirror pre { border-radius: 0px; border-width: 0px; background: 0px 0px; font-family: inherit; font-size: inherit; margin: 0px; white-space: pre; word-wrap: normal; color: inherit; z-index: 2; position: relative; overflow: visible; }
.CodeMirror-wrap pre { word-wrap: break-word; white-space: pre-wrap; word-break: normal; }
.CodeMirror-code pre { border-right: 30px solid transparent; width: fit-content; }
.CodeMirror-wrap .CodeMirror-code pre { border-right: none; width: auto; }
.CodeMirror-linebackground { position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 0; }
.CodeMirror-linewidget { position: relative; z-index: 2; overflow: auto; }
.CodeMirror-wrap .CodeMirror-scroll { overflow-x: hidden; }
.CodeMirror-measure { position: absolute; width: 100%; height: 0px; overflow: hidden; visibility: hidden; }
.CodeMirror-measure pre { position: static; }
.CodeMirror div.CodeMirror-cursor { position: absolute; border-right: none; width: 0px; visibility: hidden; }
.CodeMirror-focused div.CodeMirror-cursor { visibility: inherit; }
.CodeMirror-selected { background: rgb(217, 217, 217); }
.CodeMirror-focused .CodeMirror-selected { background: rgb(215, 212, 240); }
.cm-searching { background: rgba(255, 255, 0, 0.4); }
@media print {
.CodeMirror div.CodeMirror-cursor { visibility: hidden; }
}
.CodeMirror-lint-markers { width: 16px; }
.CodeMirror-lint-tooltip { background-color: infobackground; border: 1px solid rgb(0, 0, 0); border-radius: 4px; color: infotext; font-family: var(--monospace); overflow: hidden; padding: 2px 5px; position: fixed; white-space: pre-wrap; z-index: 10000; max-width: 600px; opacity: 0; transition: opacity 0.4s; font-size: 0.8em; }
.CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning { background-position: left bottom; background-repeat: repeat-x; }
.CodeMirror-lint-mark-error { background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg=="); }
.CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning { background-position: center center; background-repeat: no-repeat; cursor: pointer; display: inline-block; height: 16px; width: 16px; vertical-align: middle; position: relative; }
.CodeMirror-lint-message-error, .CodeMirror-lint-message-warning { padding-left: 18px; background-position: left top; background-repeat: no-repeat; }
.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error { background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII="); }
.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning { background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII="); }
.CodeMirror-lint-marker-multiple { background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC"); background-repeat: no-repeat; background-position: right bottom; width: 100%; height: 100%; }
:root { --control-text-color: #777; }
@font-face { font-family: Merriweather; font-style: normal; font-weight: 300; src: local("Merriweather Light"), local("Merriweather-Light"), url("./pixyll/Merriweather-Light.ttf"); }
@font-face { font-family: Merriweather; font-style: normal; font-weight: 900; src: local("Merriweather Heavy"), local("Merriweather-Heavy"), url("./pixyll/Merriweather-Bold.ttf"); }
@font-face { font-family: Merriweather; font-style: italic; font-weight: 300; src: local("Merriweather Light Italic"), local("Merriweather-LightItalic"), url("./pixyll/Merriweather-LightItalic.ttf"); }
@font-face { font-family: Merriweather; font-style: italic; font-weight: 900; src: local("Merriweather Heavy Italic"), local("Merriweather-HeavyItalic"), url("./pixyll/Merriweather-BoldItalic.ttf"); }
@font-face { font-family: Lato; font-style: normal; font-weight: 300; src: local("Lato Light"), local("Lato-Light"), url("./pixyll/Lato-Light.ttf"); }
@font-face { font-family: Lato; font-style: normal; font-weight: 900; src: local("Lato Black"), local("Lato-Blcak"), url("./pixyll/Lato-Black.ttf"); }
@font-face { font-family: Lato; font-style: normal; font-weight: bold; src: local("Lato Black"), local("Lato-Blcak"), url("./pixyll/Lato-Black.ttf"); }
@font-face { font-family: Lato; font-style: italic; font-weight: 900; src: local("Lato BlackItalic"), local("Lato-BlackItalic"), url("./pixyll/Lato-BlackItalic.ttf"); }
@font-face { font-family: Lato; font-style: italic; font-weight: bold; src: local("Lato BlackItalic"), local("Lato-BlackItalic"), url("./pixyll/Lato-BlackItalic.ttf"); }
h1, .h1, .f1 { font-size: 2rem; line-height: 2.5rem; }
h2, .h2, .f2 { font-size: 1.5rem; line-height: 2rem; }
h3, .h3, .f3 { font-size: 1.25rem; line-height: 1.5rem; }
p, .p, .f4, h4, h5, h6, dl, ol, ul, pre[cid], div[cid], #typora-source { font-size: 1.125rem; line-height: 1.5rem; }
h4 { font-size: 1.13rem; }
body { font-family: Merriweather, "PT Serif", Georgia, "Times New Roman", STSong, serif; line-height: 1.5rem; font-weight: 400; }
#write { max-width: 914px; color: rgb(51, 51, 51); }
img { width: auto; max-width: 100%; }
body { font-size: 1.5rem; box-sizing: border-box; }
.md-table-edit { background: rgb(237, 237, 237); padding-top: 4px; }
table { width: 100%; font-size: 1.125rem; }
table > thead > tr > th, table > thead > tr > td, table > tbody > tr > th, table > tbody > tr > td, table > tfoot > tr > th, table > tfoot > tr > td { padding: 12px; line-height: 1.2; vertical-align: top; border-top: 1px solid rgb(51, 51, 51); }
table > thead > tr > th { vertical-align: bottom; border-bottom: 2px solid rgb(51, 51, 51); }
table > caption + thead > tr:first-child > th, table > caption + thead > tr:first-child > td, table > colgroup + thead > tr:first-child > th, table > colgroup + thead > tr:first-child > td, table > thead:first-child > tr:first-child > th, table > thead:first-child > tr:first-child > td { border-top: 0px; }
table > tbody + tbody { border-top: 2px solid rgb(51, 51, 51); }
p { font-weight: 300; line-height: 1.5; }
abbr { border-bottom: 1px dotted black; cursor: help; }
pre, code { font-family: Menlo, Monaco, "Courier New", monospace; }
code, .md-fences { color: rgb(122, 122, 122); }
.md-fences .CodeMirror.CodeMirror-wrap { top: -1.5em; margin-bottom: -1.5em; }
.md-fences { padding: 1.125em; margin-bottom: 0.88em; font-size: 1rem; border: 1px solid rgb(122, 122, 122); }
blockquote { padding: 1.33em; font-style: italic; border-left: 5px solid rgb(122, 122, 122); color: rgb(85, 85, 85); }
blockquote em { color: rgb(0, 0, 0); }
blockquote footer { font-size: 0.85rem; font-style: normal; background-color: rgb(255, 255, 255); color: rgb(122, 122, 122); border-color: transparent; }
h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6 { font-family: Lato, "Helvetica Neue", Helvetica, sans-serif; font-weight: 900; line-height: 1.2; margin: 1em 0px 0.5em; }
@media screen and (min-width: 48em) {
.h1, h1 { font-size: 3.25rem; }
.h2, h2 { font-size: 2.298rem; }
.h3, h3 { font-size: 1.625rem; }
.h4, h4 { font-size: 1.3rem; }
#write > h4.md-focus::before, #write > h5.md-focus::before, #write > h6.md-focus::before { top: 1px; }
.p, p, li { font-size: 1.25rem; line-height: 1.8; }
table { font-size: 1.25rem; }
}
@media (max-width: 48em) {
blockquote { margin-left: 1rem; margin-right: 0px; padding: 0.5em; }
.h1, h1 { font-size: 2.827rem; }
.h2, h2 { font-size: 1.999rem; }
.h3, h3 { font-size: 1.413rem; }
.h4, h4 { font-size: 1.3rem; }
}
@media screen and (min-width: 64em) {
.h1, h1 { font-size: 4.498rem; }
.h2, h2 { font-size: 2.29rem; }
.h3, h3 { font-size: 1.9rem; }
.h4, h4 { font-size: 1.591rem; }
#write > h4.md-focus::before { top: 4px; }
}
a { color: rgb(70, 63, 92); text-decoration: underline; }
#write { padding-top: 2rem; }
#write pre.md-meta-block { min-height: 35px; padding: 2000px 1em 10px 0px; white-space: pre; border-width: 0px 30px; border-top-style: initial; border-bottom-style: initial; border-top-color: initial; border-bottom-color: initial; border-image: initial; border-left-style: solid; border-left-color: rgb(248, 248, 248); border-right-style: solid; border-right-color: rgb(248, 248, 248); width: 100vw; max-width: calc(100% + 60px); margin-left: -30px; margin-bottom: 2em; margin-top: -2010px; line-height: 1.5em; color: rgb(122, 122, 122); background-color: rgb(250, 250, 250); font-family: Lato, "Helvetica Neue", Helvetica, sans-serif; font-weight: 300; clear: both; font-size: 1.125rem; }
.md-image > .md-meta { color: rgb(70, 63, 92); }
.footnotes { font-size: 1.1rem; }
.md-tag { font-family: Lato, "Helvetica Neue", Helvetica, sans-serif; }
.code-tooltip { background: white; }
.code-tooltip-content { font-size: 1.1rem; }
.task-list { padding-left: 0px; }
.md-task-list-item { padding-left: 34px; }
.md-task-list-item > input { width: 1.25rem; height: 1.25rem; display: block; -webkit-appearance: initial; top: -2px; margin-left: -1.6em; margin-top: calc(1rem - 7px); }
.md-task-list-item > input:focus { outline: none; box-shadow: none; }
.md-task-list-item > input::before { border: 1px solid rgb(85, 85, 85); border-radius: 1.5rem; width: 1.5rem; height: 1.5rem; background: rgb(255, 255, 255); content: " "; transition: background-color 200ms ease-in-out; display: block; }
.md-task-list-item > input:checked::before, .md-task-list-item > input[checked]::before { background: rgb(51, 51, 51); border-width: 2px; display: inline-block; transition: background-color 200ms ease-in-out; }
.md-task-list-item > input:checked::after, .md-task-list-item > input[checked]::after { opacity: 1; }
.md-task-list-item > input::after { transition: opacity 0.05s ease-in-out; transform: rotate(-45deg); position: absolute; top: 0.4375rem; left: 0.28125rem; width: 0.9375rem; height: 0.5rem; border-width: 0px 0px 3px 3px; border-bottom-style: solid; border-left-style: solid; border-bottom-color: rgb(255, 255, 255); border-left-color: rgb(255, 255, 255); border-image: initial; border-top-style: initial; border-top-color: initial; border-right-style: initial; border-right-color: initial; content: " "; opacity: 0; }
.md-tag { color: inherit; }
.md-toc:focus .md-toc-content { margin-top: 19px; }
#typora-sidebar { font-size: 1rem !important; }
.html-for-mac #typora-sidebar { background-color: white; }
.outline-content li, .outline-content ul { font-size: 1rem !important; }
.outline-title { line-height: inherit; margin-top: 10px; }
.outline-expander { width: 18px; }
.outline-expander::before { content: "+"; font-family: inherit; color: rgb(108, 108, 108); font-size: 1.5rem; top: 0.1rem; }
.outline-expander:hover::before { content: "+"; }
.outline-item-open > .outline-item > .outline-expander::before { content: "-"; }
#typora-source { font-family: Courier, monospace; color: rgb(106, 106, 106); }
.os-windows #typora-source { font-family: inherit; }
.cm-s-typora-default .cm-header, .cm-s-typora-default .cm-property, .CodeMirror.cm-s-typora-default div.CodeMirror-cursor { color: rgb(66, 139, 202); }
.cm-s-typora-default .cm-atom, .cm-s-typora-default .cm-number { color: rgb(119, 119, 119); }
.preference-item-hint { margin-top: 16px; }
.md-diagram-panel { margin-top: 24px; margin-left: -1.2em; }
.typora-export p {white-space: normal;}
</style>
</head>
<body class='typora-export os-windows' >
<div id='write' class = 'is-node'><h1><a name='header-n0' class='md-header-anchor '></a>Funktionale Programmierung mit Haskell</h1><h2><a name='header-n2' class='md-header-anchor '></a>Rekursion</h2><pre class="md-fences md-end-block md-focus" lang="haskell" style="break-inside: unset;"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 256px; left: 136.172px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><span><span></span>x</span></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="" style="position: relative;"><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- normal recursion</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fak</span> <span class="cm-variable">n</span> <span class="cm-keyword">=</span> <span class="cm-keyword">if</span> (<span class="cm-variable">n</span><span class="cm-builtin">==</span><span class="cm-number">0</span>) <span class="cm-keyword">then</span> <span class="cm-number">1</span> <span class="cm-keyword">else</span> <span class="cm-variable">n</span> <span class="cm-builtin">*</span> <span class="cm-variable">fak</span> (<span class="cm-variable">n</span><span class="cm-builtin">-</span><span class="cm-number">1</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- linear recursive, but not end recursive</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fak'</span> <span class="cm-variable">n</span> <span class="cm-keyword">=</span> <span class="cm-keyword">if</span> (<span class="cm-variable">n</span><span class="cm-builtin">==</span><span class="cm-number">0</span>) <span class="cm-keyword">then</span> <span class="cm-number">1</span> <span class="cm-keyword">else</span> (<span class="cm-variable">n</span> <span class="cm-builtin">*</span> <span class="cm-variable">fak</span> (<span class="cm-variable">n</span><span class="cm-builtin">-</span><span class="cm-number">1</span>))</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">--using accumulator. end recursive.</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fakAcc</span> <span class="cm-variable">n</span> <span class="cm-variable">acc</span> <span class="cm-keyword">=</span> <span class="cm-keyword">if</span> (<span class="cm-variable">n</span><span class="cm-builtin">==</span><span class="cm-number">0</span>) <span class="cm-keyword">then</span> <span class="cm-variable">acc</span> <span class="cm-keyword">else</span> <span class="cm-variable">fakAcc</span> (<span class="cm-variable">n</span><span class="cm-builtin">-</span><span class="cm-number">1</span>) (<span class="cm-variable">n</span><span class="cm-builtin">*</span><span class="cm-variable">acc</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fak''</span> <span class="cm-variable">n</span> <span class="cm-keyword">=</span> <span class="cm-variable">fakAcc</span> <span class="cm-variable">n</span> <span class="cm-number">1</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- fibbonacci</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fib</span> <span class="cm-variable">n</span></span></pre><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">|</span> (<span class="cm-variable">n</span> <span class="cm-builtin">==</span> <span class="cm-number">0</span>) <span class="cm-keyword">=</span> <span class="cm-number">0</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">|</span> (<span class="cm-variable">n</span> <span class="cm-builtin">==</span> <span class="cm-number">1</span>) <span class="cm-keyword">=</span> <span class="cm-number">1</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">|</span> <span class="cm-builtin">otherwise</span> <span class="cm-keyword">=</span> <span class="cm-variable">fib</span> (<span class="cm-variable">n</span> <span class="cm-builtin">-</span> <span class="cm-number">1</span>) <span class="cm-builtin">+</span> <span class="cm-variable">fib</span> (<span class="cm-variable">n</span> <span class="cm-builtin">-</span> <span class="cm-number">2</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- fibbonacci end recursive</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fibAcc</span> <span class="cm-variable">n</span> <span class="cm-variable">n1</span> <span class="cm-variable">n2</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">|</span> (<span class="cm-variable">n</span> <span class="cm-builtin">==</span> <span class="cm-number">0</span>) <span class="cm-keyword">=</span> <span class="cm-variable">n1</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">|</span> (<span class="cm-variable">n</span> <span class="cm-builtin">==</span> <span class="cm-number">1</span>) <span class="cm-keyword">=</span> <span class="cm-variable">n2</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">|</span> <span class="cm-builtin">otherwise</span> <span class="cm-keyword">=</span> <span class="cm-variable">fibAcc</span> (<span class="cm-variable">n</span> <span class="cm-builtin">-</span> <span class="cm-number">1</span>) <span class="cm-variable">n2</span> (<span class="cm-variable">n1</span> <span class="cm-builtin">+</span> <span class="cm-variable">n2</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fib</span> <span class="cm-variable">n</span> <span class="cm-keyword">=</span> <span class="cm-variable">fibAcc</span> <span class="cm-variable">n</span> <span class="cm-number">0</span> <span class="cm-number">1</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 470px;"></div><div class="CodeMirror-gutters" style="display: none; height: 500px;"></div></div></div></pre><h2><a name='header-n4' class='md-header-anchor '></a>Listen</h2><pre class="md-fences md-end-block" lang="haskell" style="break-inside: unset;"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- length of a list</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">length</span> <span class="cm-variable">l</span> <span class="cm-keyword">=</span> <span class="cm-keyword">if</span> (<span class="cm-builtin">null</span> <span class="cm-variable">l</span>) <span class="cm-keyword">then</span> <span class="cm-number">0</span> <span class="cm-keyword">else</span> <span class="cm-number">1</span> <span class="cm-builtin">+</span> (<span class="cm-builtin">length</span> (<span class="cm-builtin">tail</span> <span class="cm-variable">l</span>))</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- is the element y in the list?</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">isIn</span> [] <span class="cm-variable">y</span> <span class="cm-keyword">=</span> <span class="cm-builtin">False</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">isIn</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span>) <span class="cm-variable">y</span> <span class="cm-keyword">=</span> <span class="cm-keyword">if</span> (<span class="cm-variable">x</span> <span class="cm-builtin">==</span> <span class="cm-variable">y</span>) <span class="cm-keyword">then</span> <span class="cm-builtin">True</span> <span class="cm-keyword">else</span> <span class="cm-variable">isIn</span> <span class="cm-variable">xs</span> <span class="cm-variable">y</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- get the maximum element in the list</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">maximum</span> [] <span class="cm-keyword">=</span> <span class="cm-builtin">error</span> <span class="cm-string">"empty"</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">maximum</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span>[]) <span class="cm-keyword">=</span> <span class="cm-variable">x</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">maximum</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span>) <span class="cm-keyword">=</span> <span class="cm-builtin">max</span> <span class="cm-variable">x</span> (<span class="cm-builtin">maximum</span> <span class="cm-variable">xs</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Append (Infix: a++b), O(length left)</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">app</span> [] <span class="cm-variable">r</span> <span class="cm-keyword">=</span> <span class="cm-variable">r</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">app</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span>) <span class="cm-variable">r</span> <span class="cm-keyword">=</span> <span class="cm-variable">x</span><span class="cm-keyword">:</span>(<span class="cm-variable">app</span> <span class="cm-variable">xs</span> <span class="cm-variable">r</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- reverse list</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">rev</span> [] <span class="cm-keyword">=</span> []</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">rev</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span>) <span class="cm-keyword">=</span> <span class="cm-variable">app</span> (<span class="cm-variable">rev</span> <span class="cm-variable">xs</span>) [<span class="cm-variable">x</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- other functions</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">head</span> <span class="cm-variable">l</span> <span class="cm-comment">-- first element of list</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">tail</span> <span class="cm-variable">l</span> <span class="cm-comment">-- list without first element</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">take</span> <span class="cm-variable">n</span> <span class="cm-variable">l</span> <span class="cm-comment">-- first n elements of l</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">drop</span> <span class="cm-variable">n</span> <span class="cm-variable">l</span> <span class="cm-comment">-- l without first n elemenets</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- map apply a function to all list members</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">map</span> <span class="cm-keyword">::</span> (<span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span>) <span class="cm-keyword">-></span> [<span class="cm-variable">s</span>] <span class="cm-keyword">-></span> [<span class="cm-variable">t</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">map</span> <span class="cm-variable">f</span> [] <span class="cm-keyword">=</span> []</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">map</span> <span class="cm-variable">f</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span>) <span class="cm-keyword">=</span> (<span class="cm-variable">f</span> <span class="cm-variable">x</span>) <span class="cm-keyword">:</span> <span class="cm-builtin">map</span> <span class="cm-variable">f</span> <span class="cm-variable">xs</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- filter a list</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">filter</span> <span class="cm-keyword">::</span> (<span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Bool</span>) <span class="cm-keyword">-></span> [<span class="cm-variable">t</span>] <span class="cm-keyword">-></span> [<span class="cm-variable">t</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">filter</span> <span class="cm-builtin">pred</span> [] <span class="cm-keyword">=</span> []</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">filter</span> <span class="cm-builtin">pred</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span>) <span class="cm-keyword">=</span> <span class="cm-keyword">if</span> <span class="cm-builtin">pred</span> <span class="cm-variable">x</span> <span class="cm-keyword">then</span> <span class="cm-variable">x</span><span class="cm-keyword">:</span>(<span class="cm-builtin">filter</span> <span class="cm-builtin">pred</span> <span class="cm-variable">xs</span>) <span class="cm-keyword">else</span> <span class="cm-builtin">filter</span> <span class="cm-builtin">pred</span> <span class="cm-variable">xs</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 743px;"></div><div class="CodeMirror-gutters" style="display: none; height: 773px;"></div></div></div></pre><pre class="md-fences md-end-block" lang="haskell" style="break-inside: unset;"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- intervals</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">[<span class="cm-variable">a</span><span class="cm-keyword">..</span><span class="cm-variable">b</span>] <span class="cm-keyword">=</span> [<span class="cm-variable">a</span>, <span class="cm-variable">a</span><span class="cm-builtin">+</span><span class="cm-number">1</span>, <span class="cm-keyword">..</span><span class="cm-builtin">.</span>, <span class="cm-variable">b</span><span class="cm-builtin">-</span><span class="cm-number">1</span>, <span class="cm-variable">b</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- list comprehensions</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">[<span class="cm-variable">e|q1</span>, <span class="cm-keyword">..</span><span class="cm-builtin">.</span>, <span class="cm-variable">qn</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">[<span class="cm-variable">f</span> <span class="cm-variable">x</span> <span class="cm-variable">|</span> <span class="cm-variable">x</span><span class="cm-keyword"><-</span><span class="cm-variable">l</span>] <span class="cm-variable"><=></span> <span class="cm-builtin">map</span> (<span class="cm-keyword">\</span><span class="cm-variable">x</span><span class="cm-keyword">-></span><span class="cm-variable">f</span> <span class="cm-variable">x</span>) <span class="cm-variable">l</span> <span class="cm-variable"><=></span> <span class="cm-builtin">map</span> <span class="cm-variable">f</span> <span class="cm-variable">l</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">[<span class="cm-variable">x</span> <span class="cm-variable">|</span> <span class="cm-variable">x</span><span class="cm-keyword"><-</span><span class="cm-variable">l</span>, <span class="cm-builtin">pred</span> <span class="cm-variable">x</span>] <span class="cm-variable"><=></span> <span class="cm-builtin">filter</span> (<span class="cm-keyword">\</span><span class="cm-variable">x</span> <span class="cm-keyword">-></span> <span class="cm-builtin">pred</span> <span class="cm-variable">x</span>) <span class="cm-variable">l</span> <span class="cm-variable"><=></span> <span class="cm-builtin">filter</span> <span class="cm-builtin">pred</span> <span class="cm-variable">l</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">[<span class="cm-variable">f</span> <span class="cm-variable">x</span> <span class="cm-variable">|</span> <span class="cm-variable">x</span><span class="cm-keyword"><-</span><span class="cm-variable">l</span>, <span class="cm-builtin">pred</span> <span class="cm-variable">x</span>] <span class="cm-variable"><=></span> <span class="cm-builtin">map</span> <span class="cm-variable">f</span> (<span class="cm-builtin">filter</span> <span class="cm-builtin">pred</span> <span class="cm-variable">l</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">squares</span> <span class="cm-variable">n</span> <span class="cm-keyword">=</span> [ <span class="cm-variable">x</span><span class="cm-builtin">*</span><span class="cm-variable">x</span> <span class="cm-variable">|</span> <span class="cm-variable">x</span> <span class="cm-keyword"><-</span> [<span class="cm-number">0</span><span class="cm-keyword">..</span><span class="cm-variable">n</span>]]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">primepowers</span> <span class="cm-variable">n</span> <span class="cm-keyword">=</span> [<span class="cm-variable">pow2</span> <span class="cm-variable">p</span> <span class="cm-variable">i</span> <span class="cm-variable">|</span> <span class="cm-variable">p</span> <span class="cm-keyword"><-</span> <span class="cm-variable">primes</span>, <span class="cm-variable">i</span> <span class="cm-keyword"><-</span> [<span class="cm-number">1</span><span class="cm-keyword">..</span><span class="cm-variable">n</span>]] <span class="cm-comment">-- qualifiers are being applied to from right to left.</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- prime sieve</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">primes</span> <span class="cm-keyword">::</span> <span class="cm-builtin">Integer</span> <span class="cm-keyword">-></span> [<span class="cm-builtin">Integer</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">primes</span> <span class="cm-variable">n</span> <span class="cm-keyword">=</span> <span class="cm-variable">sieve</span> [<span class="cm-number">2</span><span class="cm-keyword">..</span><span class="cm-variable">n</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">where</span> <span class="cm-variable">sieve</span> [] <span class="cm-keyword">=</span> []</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">sieve</span> (<span class="cm-variable">p</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span>) <span class="cm-keyword">=</span> <span class="cm-variable">p</span> <span class="cm-keyword">:</span> <span class="cm-variable">sieve</span> (<span class="cm-builtin">filter</span> (<span class="cm-builtin">not</span> <span class="cm-builtin">.</span> <span class="cm-variable">multipleOf</span> <span class="cm-variable">p</span>) <span class="cm-variable">xs</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">multipleOf</span> <span class="cm-variable">p</span> <span class="cm-variable">x</span> <span class="cm-keyword">=</span> <span class="cm-variable">x</span> <span class="cm-error">‘</span><span class="cm-variable">mod‘</span> <span class="cm-variable">p</span> <span class="cm-builtin">==</span> <span class="cm-number">0</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 386px;"></div><div class="CodeMirror-gutters" style="display: none; height: 416px;"></div></div></div></pre><p> </p><h2><a name='header-n9' class='md-header-anchor '></a>Kombinatoren</h2><h3><a name='header-n10' class='md-header-anchor '></a>foldr, foldl</h3><pre class="md-fences md-end-block" lang="haskell" style="break-inside: unset;"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">foldr</span> <span class="cm-keyword">::</span> (<span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span>) <span class="cm-keyword">-></span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> [<span class="cm-variable">s</span>] <span class="cm-keyword">-></span> <span class="cm-variable">t</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">foldr</span> <span class="cm-variable">op</span> <span class="cm-variable">i</span> [] <span class="cm-keyword">=</span> <span class="cm-variable">i</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">foldr</span> <span class="cm-variable">op</span> <span class="cm-variable">i</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span>) <span class="cm-keyword">=</span> <span class="cm-variable">op</span> <span class="cm-variable">x</span> (<span class="cm-builtin">foldr</span> <span class="cm-variable">op</span> <span class="cm-variable">i</span> <span class="cm-variable">xs</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">foldl</span> <span class="cm-keyword">::</span> (<span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span>) <span class="cm-keyword">-></span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> [<span class="cm-variable">s</span>] <span class="cm-keyword">-></span> <span class="cm-variable">t</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">foldl</span> <span class="cm-variable">op</span> <span class="cm-variable">i</span> [] <span class="cm-keyword">=</span> <span class="cm-variable">i</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">foldl</span> <span class="cm-variable">op</span> <span class="cm-variable">i</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span>) <span class="cm-keyword">=</span> <span class="cm-builtin">foldl</span> <span class="cm-variable">op</span> (<span class="cm-variable">op</span> <span class="cm-variable">i</span> <span class="cm-variable">x</span>) <span class="cm-variable">xs</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- examples</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">sum</span> <span class="cm-keyword">::</span> [<span class="cm-builtin">Int</span>] <span class="cm-keyword">-></span> <span class="cm-builtin">Int</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">sum</span> <span class="cm-keyword">=</span> <span class="cm-builtin">foldr</span> (<span class="cm-builtin">+</span>) <span class="cm-number">0</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">product</span> <span class="cm-keyword">::</span> [<span class="cm-builtin">Int</span>] <span class="cm-keyword">-></span> <span class="cm-builtin">Int</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">product</span> <span class="cm-keyword">=</span> <span class="cm-builtin">foldr</span> (<span class="cm-builtin">*</span>) <span class="cm-number">1</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">listlength</span> <span class="cm-keyword">::</span> [<span class="cm-variable">t</span>] <span class="cm-keyword">-></span> <span class="cm-builtin">Int</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">listlength</span> <span class="cm-keyword">=</span> <span class="cm-builtin">foldr</span> (<span class="cm-keyword">\</span><span class="cm-variable">x</span> <span class="cm-variable">n</span> <span class="cm-keyword">-></span> <span class="cm-variable">n</span> <span class="cm-builtin">+</span> <span class="cm-number">1</span>) <span class="cm-number">0</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">sentenceLength</span> <span class="cm-keyword">::</span> [<span class="cm-builtin">String</span>] <span class="cm-keyword">-></span> <span class="cm-builtin">Int</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">sentenceLength</span> <span class="cm-keyword">=</span> <span class="cm-builtin">foldr</span> (<span class="cm-keyword">\</span><span class="cm-variable">l</span> <span class="cm-variable">n</span> <span class="cm-keyword">-></span> <span class="cm-builtin">length</span> <span class="cm-variable">l</span> <span class="cm-builtin">+</span> <span class="cm-variable">n</span>) <span class="cm-number">0</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">app</span> <span class="cm-keyword">::</span> [<span class="cm-variable">t</span>] <span class="cm-keyword">-></span> [<span class="cm-variable">t</span>] <span class="cm-keyword">-></span> [<span class="cm-variable">t</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">app</span> <span class="cm-variable">left</span> <span class="cm-variable">right</span> <span class="cm-keyword">=</span> <span class="cm-builtin">foldr</span> (<span class="cm-keyword">:</span>) <span class="cm-variable">right</span> <span class="cm-variable">left</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">rev</span> <span class="cm-keyword">::</span> [<span class="cm-variable">t</span>] <span class="cm-keyword">-></span> [<span class="cm-variable">t</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">rev</span> <span class="cm-keyword">=</span> <span class="cm-builtin">foldl</span> <span class="cm-variable">cons</span> []</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">where</span> <span class="cm-variable">cons</span> <span class="cm-variable">xs</span> <span class="cm-variable">x</span> <span class="cm-keyword">=</span> <span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" class="cm-tab-wrap-hack" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">flatten</span> <span class="cm-keyword">::</span> [[<span class="cm-variable">t</span>]] <span class="cm-keyword">-></span> [<span class="cm-variable">t</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">flatten</span> <span class="cm-keyword">=</span> <span class="cm-builtin">foldr</span> <span class="cm-variable">app</span> []</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">map</span> <span class="cm-keyword">::</span> (<span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span>) <span class="cm-keyword">-></span> [<span class="cm-variable">s</span>] <span class="cm-keyword">-></span> [<span class="cm-variable">t</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">map</span> <span class="cm-variable">f</span> <span class="cm-keyword">=</span> <span class="cm-builtin">foldr</span> (<span class="cm-keyword">\</span><span class="cm-variable">x</span> <span class="cm-variable">l</span> <span class="cm-keyword">-></span> <span class="cm-variable">f</span> <span class="cm-variable">x</span> <span class="cm-keyword">:</span> <span class="cm-variable">l</span>) []</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 701px;"></div><div class="CodeMirror-gutters" style="display: none; height: 731px;"></div></div></div></pre><h3><a name='header-n12' class='md-header-anchor '></a>Zip</h3><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- combine two lists element-wise with a combinator function</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">zipWith</span> <span class="cm-keyword">::</span> (<span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-variable">u</span>) <span class="cm-keyword">-></span> [<span class="cm-variable">s</span>] <span class="cm-keyword">-></span> [<span class="cm-variable">t</span>] <span class="cm-keyword">-></span> [<span class="cm-variable">u</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">zipWith</span> <span class="cm-variable">f</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">xs</span>) (<span class="cm-variable">y</span><span class="cm-keyword">:</span><span class="cm-variable">ys</span>) <span class="cm-keyword">=</span> <span class="cm-variable">f</span> <span class="cm-variable">x</span> <span class="cm-variable">y</span> <span class="cm-keyword">:</span> <span class="cm-builtin">zipWith</span> <span class="cm-variable">f</span> <span class="cm-variable">xs</span> <span class="cm-variable">ys</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">zipWith</span> <span class="cm-variable">f</span> <span class="cm-variable">xs</span> <span class="cm-variable">ys</span> <span class="cm-keyword">=</span> []</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">zip</span> <span class="cm-keyword">=</span> <span class="cm-builtin">zipWith</span> (,) <span class="cm-comment">-- combine two lists into list of two-tuples</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Example: Hamming distance</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">hamming</span> <span class="cm-variable">l</span> <span class="cm-variable">r</span> <span class="cm-keyword">=</span> <span class="cm-builtin">sum</span> (<span class="cm-builtin">zipWith</span> <span class="cm-variable">differs</span> <span class="cm-variable">l</span> <span class="cm-variable">r</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">where</span> <span class="cm-variable">differs</span> <span class="cm-variable">x</span> <span class="cm-variable">y</span> <span class="cm-keyword">=</span> <span class="cm-keyword">if</span> (<span class="cm-variable">x</span> <span class="cm-builtin">==</span> <span class="cm-variable">y</span>) <span class="cm-keyword">then</span> <span class="cm-number">0</span> <span class="cm-keyword">else</span> <span class="cm-number">1</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 239px;"></div><div class="CodeMirror-gutters" style="display: none; height: 269px;"></div></div></div></pre><h2><a name='header-n14' class='md-header-anchor '></a>Streams</h2><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- iterate loop: (f,a) => [a, f(a), f(f(a)), f(f(f(a))), ...]</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">iterate</span> <span class="cm-keyword">::</span> (<span class="cm-variable">a</span> <span class="cm-keyword">-></span> <span class="cm-variable">a</span>) <span class="cm-keyword">-></span> <span class="cm-variable">a</span> <span class="cm-keyword">-></span> [<span class="cm-variable">a</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">iterate</span> <span class="cm-variable">f</span> <span class="cm-variable">a</span> <span class="cm-keyword">=</span> <span class="cm-variable">a</span> <span class="cm-keyword">:</span> <span class="cm-builtin">iterate</span> <span class="cm-variable">f</span> (<span class="cm-variable">f</span> <span class="cm-variable">a</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">iterate</span> <span class="cm-variable">f</span> <span class="cm-variable">x</span> <span class="cm-builtin">!!</span> <span class="cm-number">23</span> <span class="cm-comment">-- iterate only 23 times</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">takeWhile</span> <span class="cm-keyword">::</span> (<span class="cm-variable">a</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Bool</span>) <span class="cm-keyword">-></span> [<span class="cm-variable">a</span>] <span class="cm-keyword">-></span> [<span class="cm-variable">a</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- takeWhile op list supplys elements from the list as long as op is true for the current list element.</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 176px;"></div><div class="CodeMirror-gutters" style="display: none; height: 206px;"></div></div></div></pre><p> </p><h2><a name='header-n18' class='md-header-anchor '></a>Approximation von Pi</h2><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">partialSums</span> <span class="cm-keyword">::</span> [<span class="cm-builtin">Double</span>] <span class="cm-keyword">-></span> [<span class="cm-builtin">Double</span>]</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">partialSums</span> (<span class="cm-variable">x</span> <span class="cm-keyword">:</span> <span class="cm-variable">xs</span>) <span class="cm-keyword">=</span> <span class="cm-variable">pSumsAcc</span> <span class="cm-variable">xs</span> <span class="cm-variable">x</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">where</span> <span class="cm-variable">pSumsAcc</span> (<span class="cm-variable">x</span> <span class="cm-keyword">:</span> <span class="cm-variable">xs</span>) <span class="cm-variable">acc</span> <span class="cm-keyword">=</span> <span class="cm-variable">acc</span> <span class="cm-keyword">:</span> (<span class="cm-variable">pSumsAcc</span> <span class="cm-variable">xs</span> (<span class="cm-variable">x</span> <span class="cm-builtin">+</span> <span class="cm-variable">acc</span>))</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">approxPi</span> <span class="cm-keyword">=</span> <span class="cm-builtin">map</span> (<span class="cm-builtin">*</span><span class="cm-number">4</span>) (<span class="cm-variable">partialSums</span> <span class="cm-variable">piSeq</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">where</span> <span class="cm-variable">piSeq</span> <span class="cm-keyword">=</span> <span class="cm-builtin">zipWith</span> (<span class="cm-builtin">/</span>) (<span class="cm-builtin">iterate</span> <span class="cm-builtin">negate</span> <span class="cm-number">1</span>) <span class="cm-variable">odds</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 113px;"></div><div class="CodeMirror-gutters" style="display: none; height: 143px;"></div></div></div></pre><h2><a name='header-n20' class='md-header-anchor '></a>Sieb des Eratosthenes</h2><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">oddPrimes</span> (<span class="cm-variable">p</span> <span class="cm-keyword">:</span> <span class="cm-variable">ps</span>) <span class="cm-keyword">=</span> <span class="cm-variable">p</span> <span class="cm-keyword">:</span> (<span class="cm-variable">oddPrimes</span> [<span class="cm-variable">p’</span> <span class="cm-variable">|</span> <span class="cm-variable">p’</span> <span class="cm-keyword"><-</span> <span class="cm-variable">ps</span>, <span class="cm-variable">p’</span> <span class="cm-error">‘</span><span class="cm-variable">mod‘</span> <span class="cm-variable">p</span> <span class="cm-builtin">/=</span> <span class="cm-number">0</span>])</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">primes</span> <span class="cm-keyword">=</span> <span class="cm-number">2</span> <span class="cm-keyword">:</span> <span class="cm-variable">oddPrimes</span> (<span class="cm-builtin">tail</span> <span class="cm-variable">odds</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">odds</span> <span class="cm-keyword">=</span> <span class="cm-number">1</span> <span class="cm-keyword">:</span> <span class="cm-builtin">map</span> (<span class="cm-builtin">+</span><span class="cm-number">2</span>) <span class="cm-variable">odds</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- in comprehension: sort out multiples of current value</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 92px;"></div><div class="CodeMirror-gutters" style="display: none; height: 122px;"></div></div></div></pre><h2><a name='header-n22' class='md-header-anchor '></a>Typen</h2><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Int</span> <span class="cm-comment">-- whole numbers, restricted size</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Integer</span> <span class="cm-comment">-- whole numbers, arbitrary size</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Float</span> <span class="cm-comment">-- floating point numbers, single precision</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Double</span> <span class="cm-comment">-- floating point numbers, double precision</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Bool</span> <span class="cm-comment">-- boolean value</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Char</span> <span class="cm-comment">-- unicode character</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 134px;"></div><div class="CodeMirror-gutters" style="display: none; height: 164px;"></div></div></div></pre><h3><a name='header-n24' class='md-header-anchor '></a>Beispiel für Typen: Mengen</h3><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">type</span> <span class="cm-variable-2">Set</span> <span class="cm-variable">t</span> <span class="cm-keyword">=</span> [<span class="cm-variable">t</span>]</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">insert</span> <span class="cm-variable">x</span> <span class="cm-variable">s</span> <span class="cm-keyword">=</span> <span class="cm-keyword">if</span> (<span class="cm-variable">isIn</span> <span class="cm-variable">s</span> <span class="cm-variable">x</span>) <span class="cm-keyword">then</span> <span class="cm-variable">s</span> <span class="cm-keyword">else</span> <span class="cm-variable">x</span><span class="cm-keyword">:</span><span class="cm-variable">s</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">delete</span> <span class="cm-variable">x</span> [] <span class="cm-keyword">=</span> []</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">delete</span> <span class="cm-variable">x</span> (<span class="cm-variable">y</span><span class="cm-keyword">:</span><span class="cm-variable">ys</span>) <span class="cm-keyword">=</span> <span class="cm-keyword">if</span> (<span class="cm-variable">x</span><span class="cm-builtin">==</span><span class="cm-variable">y</span>) <span class="cm-keyword">then</span> <span class="cm-variable">ys</span> <span class="cm-keyword">else</span> <span class="cm-variable">y</span><span class="cm-keyword">:</span>(<span class="cm-variable">delete</span> <span class="cm-variable">x</span> <span class="cm-variable">ys</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fold</span> <span class="cm-keyword">=</span> <span class="cm-builtin">foldr</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 176px;"></div><div class="CodeMirror-gutters" style="display: none; height: 206px;"></div></div></div></pre><h3><a name='header-n26' class='md-header-anchor '></a>Backtracking, Damenproblem</h3><p>Vorgehensweise</p><ul><li>Mit zulässiger Anfangskonfigurationbeginnen (leeres Brett)</li><li>Baum von zulässigen Folgekonfigurationen konstruieren und durchsuchen (weitere Damen platzieren, ohne vorhandene zu bedrohen)</li><li>Bis Lösungskonfiguration gefunden (8 Damen auf Brett)</li></ul><pre class="md-fences md-end-block" lang="haskell" style="break-inside: unset;"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">type</span> <span class="cm-variable-2">Conf</span> <span class="cm-keyword">=</span> [<span class="cm-builtin">Integer</span>] <span class="cm-comment">-- Konfiguration = Liste von Zeilenpositionen</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">successors</span> <span class="cm-keyword">::</span> <span class="cm-variable-2">Conf</span> <span class="cm-keyword">-></span> [<span class="cm-variable-2">Conf</span>] <span class="cm-comment">-- Folgekonfigurationen bestimmen</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">legal</span> <span class="cm-keyword">::</span> <span class="cm-variable-2">Conf</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Bool</span> <span class="cm-comment">-- Konfiguration auf Zulässigkeit prüfen</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">solution</span> <span class="cm-keyword">::</span> <span class="cm-variable-2">Conf</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Bool</span> <span class="cm-comment">-- Zulässige Konfiguration prüfen, ob korrekte Lösung</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">solutions</span> <span class="cm-keyword">=</span> <span class="cm-variable">backtrack</span> <span class="cm-variable">initial</span> <span class="cm-comment">-- liefert alle Lösungen (oder mit head nur erste)</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> </span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">backtrack</span> <span class="cm-keyword">::</span> <span class="cm-variable-2">Conf</span> <span class="cm-keyword">-></span> [<span class="cm-variable-2">Conf</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">backtrack</span> <span class="cm-variable">conf</span> <span class="cm-keyword">=</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">if</span> (<span class="cm-variable">solution</span> <span class="cm-variable">conf</span>) <span class="cm-keyword">then</span> [<span class="cm-variable">conf</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">else</span> <span class="cm-variable">flatten</span> (<span class="cm-builtin">map</span> <span class="cm-variable">backtrack</span> (<span class="cm-builtin">filter</span> <span class="cm-variable">legal</span> (<span class="cm-variable">successors</span> <span class="cm-variable">conf</span>)))</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" class="cm-tab-wrap-hack" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">successors</span> <span class="cm-keyword">::</span> <span class="cm-variable-2">Conf</span> <span class="cm-keyword">-></span> [<span class="cm-variable-2">Conf</span>] <span class="cm-comment">-- Folgekonfigurationen bestimmen</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">successors</span> <span class="cm-variable">board</span> <span class="cm-keyword">=</span> <span class="cm-builtin">map</span> (<span class="cm-keyword">:</span><span class="cm-variable">board</span>) [<span class="cm-number">1</span><span class="cm-keyword">..</span><span class="cm-number">8</span>] <span class="cm-comment">-- in jeder Zeile eine Dame platzieren</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">threatens</span> <span class="cm-keyword">::</span> <span class="cm-builtin">Int</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Int</span> <span class="cm-keyword">-></span> <span class="cm-variable-2">Conf</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Bool</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">threatens</span> <span class="cm-variable">diag</span> <span class="cm-variable">row</span> [] <span class="cm-keyword">=</span> <span class="cm-builtin">False</span> <span class="cm-comment">-- diag = horizontaler abstand zw 1ter und 2ter Dame</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">threatens</span> <span class="cm-variable">diag</span> <span class="cm-variable">row</span> (<span class="cm-variable">row2</span><span class="cm-keyword">:</span><span class="cm-variable">rest</span>) <span class="cm-keyword">=</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>(<span class="cm-variable">row2</span><span class="cm-builtin">==</span><span class="cm-variable">row</span><span class="cm-builtin">+</span><span class="cm-variable">diag</span>) <span class="cm-builtin">||</span> (<span class="cm-variable">row2</span><span class="cm-builtin">==</span><span class="cm-variable">row</span><span class="cm-builtin">-</span><span class="cm-variable">diag</span>) <span class="cm-builtin">||</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>(<span class="cm-variable">row2</span><span class="cm-builtin">==</span><span class="cm-variable">row</span>) <span class="cm-builtin">||</span> <span class="cm-variable">threatens</span> (<span class="cm-variable">diag</span><span class="cm-builtin">+</span><span class="cm-number">1</span>) <span class="cm-variable">row</span> <span class="cm-variable">rest</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">legal</span> <span class="cm-keyword">::</span> <span class="cm-variable-2">Conf</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Bool</span> <span class="cm-comment">-- Konfiguration auf Zulässigkeit prüfen</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">legal</span> [] <span class="cm-keyword">=</span> <span class="cm-builtin">True</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">legal</span> (<span class="cm-variable">row</span><span class="cm-keyword">:</span><span class="cm-variable">rest</span>) <span class="cm-keyword">=</span> (<span class="cm-builtin">not</span> (<span class="cm-variable">threatens</span> <span class="cm-number">1</span> <span class="cm-variable">row</span> <span class="cm-variable">rest</span>))</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">solution</span> <span class="cm-keyword">::</span> <span class="cm-variable-2">Conf</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Bool</span> <span class="cm-comment">-- Ist Konfiguration fertige Lösung? Ja wenn 8 Damen.</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">solution</span> <span class="cm-variable">board</span> <span class="cm-keyword">=</span> (<span class="cm-builtin">length</span> <span class="cm-variable">board</span>) <span class="cm-builtin">==</span> <span class="cm-number">8</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">initial</span> <span class="cm-keyword">=</span> [] <span class="cm-comment">-- Initialkonfiguration: Leeres Brett.</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 596px;"></div><div class="CodeMirror-gutters" style="display: none; height: 626px;"></div></div></div></pre><h3><a name='header-n40' class='md-header-anchor '></a>Algebraische Datentypen</h3><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">data</span> <span class="cm-variable-2">DataName</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">ConstructorName</span> <span class="cm-variable-2">Param1</span> <span class="cm-variable-2">Param2</span> <span class="cm-variable">|</span> <span class="cm-variable-2">ConstructorName2</span> <span class="cm-variable-2">Param1b</span> <span class="cm-variable-2">Param2b</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">data</span> <span class="cm-variable-2">Season</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Spring</span> <span class="cm-variable">|</span> <span class="cm-variable-2">Summer</span> <span class="cm-variable">|</span> <span class="cm-variable-2">Autumn</span> <span class="cm-variable">|</span> <span class="cm-variable-2">Winter</span> <span class="cm-comment">-- Enumeration</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">data</span> <span class="cm-variable-2">People</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Person</span> <span class="cm-builtin">String</span> <span class="cm-builtin">Int</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span> <span class="cm-variable">|</span> <span class="cm-variable-2">Adult</span> <span class="cm-builtin">String</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">jogi</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Person</span> <span class="cm-string">"Joachim Löw"</span> <span class="cm-number">50</span> <span class="cm-comment">-- jogi :: People</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">isAdult</span> (<span class="cm-variable-2">Person</span> <span class="cm-variable">name</span> <span class="cm-variable">age</span>) <span class="cm-keyword">=</span> <span class="cm-variable">age</span> <span class="cm-builtin">>=</span> <span class="cm-number">18</span> <span class="cm-comment">-- isAdult :: People -> Bool</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">isAdult</span> (<span class="cm-variable-2">Adult</span> <span class="cm-variable">name</span>) <span class="cm-keyword">=</span> <span class="cm-builtin">True</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 176px;"></div><div class="CodeMirror-gutters" style="display: none; height: 206px;"></div></div></div></pre><h3><a name='header-n42' class='md-header-anchor '></a>Polymorphe Datentypen</h3><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">data</span> <span class="cm-builtin">Maybe</span> <span class="cm-variable">t</span> <span class="cm-keyword">=</span> <span class="cm-builtin">Nothing</span> <span class="cm-variable">|</span> <span class="cm-builtin">Just</span> <span class="cm-variable">t</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Just</span> <span class="cm-builtin">True</span> <span class="cm-keyword">::</span> <span class="cm-builtin">Maybe</span> <span class="cm-builtin">Bool</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Nothing</span> <span class="cm-keyword">::</span> <span class="cm-builtin">Maybe</span> <span class="cm-builtin">String</span> <span class="cm-comment">-- Optional parameters default to String (?)</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 71px;"></div><div class="CodeMirror-gutters" style="display: none; height: 101px;"></div></div></div></pre><p>Dicht und dünn besetzte Matrizen:</p><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">data</span> <span class="cm-variable-2">Matrix</span> <span class="cm-variable">t</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Dense</span> [[<span class="cm-variable">t</span>]] <span class="cm-comment">-- list of rows</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span> <span class="cm-variable">|</span> <span class="cm-variable-2">Sparse</span> [(<span class="cm-builtin">Integer</span>,<span class="cm-builtin">Integer</span>,<span class="cm-variable">t</span>)] <span class="cm-variable">t</span> <span class="cm-comment">-- matrix values (i, j, val) and default value</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">unit</span> <span class="cm-keyword">::</span> <span class="cm-builtin">Integer</span> <span class="cm-keyword">-></span> <span class="cm-variable-2">Matrix</span> <span class="cm-builtin">Float</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">unit</span> <span class="cm-variable">n</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Sparse</span> [(<span class="cm-variable">i</span>,<span class="cm-variable">i</span>,<span class="cm-number">1.0</span>) <span class="cm-variable">|</span> <span class="cm-variable">i</span> <span class="cm-keyword"><-</span> [<span class="cm-number">1</span><span class="cm-keyword">..</span><span class="cm-variable">n</span>]] <span class="cm-number">0</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">rotation</span> <span class="cm-keyword">::</span> <span class="cm-builtin">Double</span> <span class="cm-keyword">-></span> <span class="cm-variable-2">Matrix</span> <span class="cm-builtin">Double</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">rotation</span> <span class="cm-variable">alpha</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Dense</span> [[<span class="cm-builtin">cos</span> <span class="cm-variable">alpha</span>, <span class="cm-builtin">-sin</span> <span class="cm-variable">alpha</span>], [<span class="cm-builtin">sin</span> <span class="cm-variable">alpha</span>, <span class="cm-builtin">cos</span> <span class="cm-variable">alpha</span>]]</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 197px;"></div><div class="CodeMirror-gutters" style="display: none; height: 227px;"></div></div></div></pre><h3><a name='header-n47' class='md-header-anchor '></a>Binäre Bäume</h3><pre class="md-fences md-end-block" lang="haskell" style="break-inside: unset;"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">data</span> <span class="cm-variable-2">Tree</span> <span class="cm-variable">t</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Leaf</span> <span class="cm-variable">|</span> <span class="cm-variable-2">Node</span> (<span class="cm-variable-2">Tree</span> <span class="cm-variable">t</span>) <span class="cm-variable">t</span> (<span class="cm-variable-2">Tree</span> <span class="cm-variable">t</span>) <span class="cm-comment">-- data is only in nodes, not in leafs.</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">someTree</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Node</span> (<span class="cm-variable-2">Node</span> <span class="cm-variable-2">Leaf</span> <span class="cm-number">1</span> <span class="cm-variable-2">Leaf</span>) <span class="cm-number">3</span> <span class="cm-variable-2">Leaf</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Get amount of elements stored in tree</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">size</span> <span class="cm-keyword">::</span> <span class="cm-variable-2">Tree</span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Int</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">size</span> <span class="cm-variable-2">Leaf</span> <span class="cm-keyword">=</span> <span class="cm-number">0</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">size</span> (<span class="cm-variable-2">Node</span> <span class="cm-variable">left</span> <span class="cm-variable">x</span> <span class="cm-variable">right</span>) <span class="cm-keyword">=</span> (<span class="cm-variable">size</span> <span class="cm-variable">left</span>) <span class="cm-builtin">+</span> <span class="cm-number">1</span> <span class="cm-builtin">+</span> (<span class="cm-variable">size</span> <span class="cm-variable">right</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Height of the tree</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">height</span> <span class="cm-keyword">::</span> <span class="cm-variable-2">Tree</span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Int</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">height</span> <span class="cm-variable-2">Leaf</span> <span class="cm-keyword">=</span> <span class="cm-number">0</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">height</span> (<span class="cm-variable-2">Node</span> <span class="cm-variable">left</span> <span class="cm-variable">x</span> <span class="cm-variable">right</span>) <span class="cm-keyword">=</span> <span class="cm-number">1</span> <span class="cm-builtin">+</span> (<span class="cm-builtin">max</span> (<span class="cm-variable">height</span> <span class="cm-variable">left</span>) (<span class="cm-variable">height</span> <span class="cm-variable">right</span>))</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- With fold. f has three params.</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">foldT</span> <span class="cm-keyword">::</span> (<span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable">s</span>) <span class="cm-keyword">-></span> <span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable-2">Tree</span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-variable">s</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">foldT</span> <span class="cm-variable">f</span> <span class="cm-variable">i</span> <span class="cm-variable-2">Leaf</span> <span class="cm-keyword">=</span> <span class="cm-variable">i</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">foldT</span> <span class="cm-variable">f</span> <span class="cm-variable">i</span> (<span class="cm-variable-2">Node</span> <span class="cm-variable">left</span> <span class="cm-variable">x</span> <span class="cm-variable">right</span>) <span class="cm-keyword">=</span> <span class="cm-variable">f</span> (<span class="cm-variable">foldT</span> <span class="cm-variable">f</span> <span class="cm-variable">i</span> <span class="cm-variable">left</span>) <span class="cm-variable">x</span> (<span class="cm-variable">foldT</span> <span class="cm-variable">f</span> <span class="cm-variable">i</span> <span class="cm-variable">right</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">size</span> <span class="cm-keyword">=</span> <span class="cm-variable">foldT</span> (<span class="cm-keyword">\</span><span class="cm-variable">left</span> <span class="cm-variable">x</span> <span class="cm-variable">right</span> <span class="cm-keyword">-></span> <span class="cm-variable">left</span><span class="cm-builtin">+</span><span class="cm-number">1</span><span class="cm-builtin">+</span><span class="cm-variable">right</span>) <span class="cm-number">0</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">height</span> <span class="cm-keyword">=</span> <span class="cm-variable">foldT</span> (<span class="cm-keyword">\</span><span class="cm-variable">left</span> <span class="cm-variable">x</span> <span class="cm-variable">right</span> <span class="cm-keyword">-></span> <span class="cm-number">1</span><span class="cm-builtin">+</span>(<span class="cm-builtin">max</span> <span class="cm-variable">left</span> <span class="cm-variable">right</span>)) <span class="cm-number">0</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">paths</span> <span class="cm-variable">tree</span> <span class="cm-keyword">=</span> <span class="cm-variable">foldT</span> <span class="cm-variable">consAll</span> [[]] <span class="cm-variable">tree</span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">-- paths :: Tree t -> [[t]]</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">where</span> <span class="cm-variable">consAll</span> <span class="cm-variable">left</span> <span class="cm-variable">x</span> <span class="cm-variable">right</span> <span class="cm-keyword">=</span> <span class="cm-builtin">map</span> (<span class="cm-variable">x</span><span class="cm-keyword">:</span>) (<span class="cm-variable">left</span><span class="cm-builtin">++</span><span class="cm-variable">right</span>) <span class="cm-comment">--todo?</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 470px;"></div><div class="CodeMirror-gutters" style="display: none; height: 500px;"></div></div></div></pre><h3><a name='header-n49' class='md-header-anchor '></a>Rot-Schwarz-Bäume</h3><p>Knoten sind rot oder schwarz, Blätter sind schwarz.Invarianten:</p><ul><li>Kein roter Knoten hat roten Elternknoten.</li><li>Alle vollständigen Pfade haben dieselbe Anzahl schwarzer Knoten.</li><li>Baum ist sortiert: Elemente linker Teilbaum <= KnotenElement. Elemente rechter Teilbaum >= KnotenEl.</li></ul><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">data</span> <span class="cm-variable-2">Color</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Red</span> <span class="cm-variable">|</span> <span class="cm-variable-2">Black</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">data</span> <span class="cm-variable-2">RedBlackTree</span> <span class="cm-variable">t</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Leaf</span> <span class="cm-variable">|</span> <span class="cm-variable-2">Node</span> <span class="cm-variable-2">Color</span> (<span class="cm-variable-2">RedBlackTree</span> <span class="cm-variable">t</span>) <span class="cm-variable">t</span> (<span class="cm-variable-2">RedBlackTree</span> <span class="cm-variable">t</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fold</span> <span class="cm-keyword">::</span> (<span class="cm-variable-2">Color</span> <span class="cm-keyword">-></span> <span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable">s</span>) <span class="cm-keyword">-></span> <span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable-2">RedBlackTree</span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-variable">s</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fold</span> <span class="cm-variable">f</span> <span class="cm-variable">i</span> <span class="cm-variable-2">Leaf</span> <span class="cm-keyword">=</span> <span class="cm-variable">i</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fold</span> <span class="cm-variable">f</span> <span class="cm-variable">i</span> (<span class="cm-variable-2">Node</span> <span class="cm-variable">c</span> <span class="cm-variable">left</span> <span class="cm-variable">x</span> <span class="cm-variable">right</span>) <span class="cm-keyword">=</span> <span class="cm-variable">f</span> <span class="cm-variable">c</span> (<span class="cm-variable">fold</span> <span class="cm-variable">f</span> <span class="cm-variable">i</span> <span class="cm-variable">left</span>) <span class="cm-variable">x</span> (<span class="cm-variable">fold</span> <span class="cm-variable">f</span> <span class="cm-variable">i</span> <span class="cm-variable">right</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">mapRB</span> <span class="cm-keyword">::</span> (<span class="cm-variable-2">Color</span> <span class="cm-keyword">-></span> <span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span>) <span class="cm-keyword">-></span> <span class="cm-variable-2">RedBlackTree</span> <span class="cm-variable">s</span> <span class="cm-keyword">-></span> <span class="cm-variable-2">RedBlackTree</span> <span class="cm-variable">t</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">mapRB</span> <span class="cm-variable">f</span> <span class="cm-variable-2">Leaf</span> <span class="cm-keyword">=</span> <span class="cm-variable-2">Leaf</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">mapRB</span> <span class="cm-variable">f</span> (<span class="cm-variable-2">Node</span> <span class="cm-variable">c</span> <span class="cm-variable">left</span> <span class="cm-variable">x</span> <span class="cm-variable">right</span>) <span class="cm-keyword">=</span> <span class="cm-variable-2">Node</span> <span class="cm-variable">c</span> (<span class="cm-variable">mapRB</span> <span class="cm-variable">f</span> <span class="cm-variable">left</span>) (<span class="cm-variable">f</span> <span class="cm-variable">c</span> <span class="cm-variable">x</span>) (<span class="cm-variable">mapRB</span> <span class="cm-variable">f</span> <span class="cm-variable">right</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 218px;"></div><div class="CodeMirror-gutters" style="display: none; height: 248px;"></div></div></div></pre><h2><a name='header-n65' class='md-header-anchor '></a>Typklassen</h2><pre class="md-fences md-end-block" lang="haskell" style="break-inside: unset;"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Eq</span> <span class="cm-variable">t</span><span class="cm-keyword">:</span> <span class="cm-builtin">==</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-builtin">Bool</span>, <span class="cm-builtin">/=</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-builtin">Bool</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-2">Instanzen</span><span class="cm-keyword">:</span> <span class="cm-builtin">Eq</span> <span class="cm-builtin">Integer</span>, <span class="cm-builtin">Eq</span> <span class="cm-builtin">Char</span>, <span class="cm-builtin">Eq</span> <span class="cm-builtin">Bool</span>, <span class="cm-keyword">..</span><span class="cm-builtin">.</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Ord</span> <span class="cm-variable">t</span><span class="cm-keyword">:</span> <span class="cm-builtin"><=</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-builtin">Bool</span>, <span class="cm-builtin"><</span>, <span class="cm-builtin">></span>, <span class="cm-builtin">>=</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-2">Instanzen</span><span class="cm-keyword">:</span> <span class="cm-builtin">Ord</span> <span class="cm-builtin">Float</span>, <span class="cm-builtin">Ord</span> <span class="cm-builtin">Integer</span>, <span class="cm-builtin">Ord</span> <span class="cm-builtin">Char</span>, <span class="cm-keyword">..</span><span class="cm-builtin">.</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Num</span> <span class="cm-variable">t</span><span class="cm-keyword">:</span> <span class="cm-builtin">+</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span>, <span class="cm-builtin">*</span>, <span class="cm-builtin">-</span>, <span class="cm-builtin">negate</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span>, <span class="cm-builtin">abs</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span>, <span class="cm-builtin">signum</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span>, <span class="cm-builtin">fromInteger</span> <span class="cm-keyword">::</span> <span class="cm-builtin">Integer</span><span class="cm-keyword">-></span><span class="cm-variable">t</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-2">Instanzen</span><span class="cm-keyword">:</span> <span class="cm-builtin">Num</span> <span class="cm-builtin">Float</span>, <span class="cm-builtin">Num</span> <span class="cm-builtin">Integer</span>, <span class="cm-keyword">..</span><span class="cm-builtin">.</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" class="cm-tab-wrap-hack" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Show</span> <span class="cm-variable">t</span><span class="cm-keyword">:</span> <span class="cm-builtin">show</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-builtin">String</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-2">Instanzen</span><span class="cm-keyword">:</span> <span class="cm-builtin">Show</span> <span class="cm-builtin">Float</span>, <span class="cm-builtin">Show</span> <span class="cm-builtin">Bool</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" class="cm-tab-wrap-hack" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">Enum</span> <span class="cm-variable">t</span><span class="cm-keyword">:</span> <span class="cm-builtin">succ</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span>, <span class="cm-builtin">pred</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span>, <span class="cm-builtin">toEnum</span> <span class="cm-keyword">::</span> <span class="cm-builtin">Int</span><span class="cm-keyword">-></span><span class="cm-variable">t</span>, <span class="cm-builtin">fromEnum</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-builtin">Int</span>, <span class="cm-builtin">enumFromTo</span> <span class="cm-keyword">::</span> <span class="cm-variable">t</span><span class="cm-keyword">-></span><span class="cm-variable">t</span><span class="cm-keyword">-></span>[<span class="cm-variable">t</span>]</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-2">Instanzen</span><span class="cm-keyword">:</span> <span class="cm-builtin">Enum</span> <span class="cm-builtin">Bool</span>, <span class="cm-builtin">Enum</span> <span class="cm-builtin">Int</span>, <span class="cm-builtin">Enum</span> <span class="cm-builtin">Char</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 344px;"></div><div class="CodeMirror-gutters" style="display: none; height: 374px;"></div></div></div></pre><p>Beispiel:</p><pre class="md-fences md-end-block" lang="haskell"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">class</span> (<span class="cm-builtin">Eq</span> <span class="cm-variable">t</span>) <span class="cm-keyword">where</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> (<span class="cm-builtin">==</span>) <span class="cm-keyword">::</span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Bool</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> (<span class="cm-builtin">/=</span>) <span class="cm-keyword">::</span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-variable">t</span> <span class="cm-keyword">-></span> <span class="cm-builtin">Bool</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">x</span> <span class="cm-builtin">/=</span> <span class="cm-variable">y</span> <span class="cm-keyword">=</span> <span class="cm-builtin">not</span> (<span class="cm-variable">x</span> <span class="cm-builtin">==</span> <span class="cm-variable">y</span>)<span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">-- default implementation</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">x</span> <span class="cm-builtin">==</span> <span class="cm-variable">y</span> <span class="cm-keyword">=</span> <span class="cm-builtin">not</span> (<span class="cm-variable">x</span> <span class="cm-builtin">/=</span> <span class="cm-variable">y</span>)<span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">-- default implementation</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text=""></span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">instance</span> (<span class="cm-builtin">Eq</span> <span class="cm-builtin">Bool</span>) <span class="cm-keyword">where</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">True</span> <span class="cm-builtin">==</span> <span class="cm-builtin">True</span> <span class="cm-keyword">=</span> <span class="cm-builtin">True</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">False</span> <span class="cm-builtin">==</span> <span class="cm-builtin">False</span> <span class="cm-keyword">=</span> <span class="cm-builtin">True</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">False</span> <span class="cm-builtin">==</span> <span class="cm-builtin">True</span> <span class="cm-keyword">=</span> <span class="cm-builtin">False</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">True</span> <span class="cm-builtin">==</span> <span class="cm-builtin">False</span> <span class="cm-keyword">=</span> <span class="cm-builtin">False</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 239px;"></div><div class="CodeMirror-gutters" style="display: none; height: 269px;"></div></div></div></pre><p>Weiteres Beispiel</p><pre class="md-fences md-end-block" lang="haskell" style="break-inside: unset;"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;"></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 30px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">class</span> <span class="cm-variable-2">Unit</span> <span class="cm-variable">u</span> <span class="cm-keyword">where</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">plus</span> <span class="cm-keyword">::</span> <span class="cm-variable">u</span> <span class="cm-keyword">-></span> <span class="cm-variable">u</span> <span class="cm-keyword">-></span> <span class="cm-variable">u</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">minus</span> <span class="cm-keyword">::</span> <span class="cm-variable">u</span> <span class="cm-keyword">-></span> <span class="cm-variable">u</span> <span class="cm-keyword">-></span> <span class="cm-variable">u</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">ntimes</span> <span class="cm-keyword">::</span> <span class="cm-builtin">Double</span> <span class="cm-keyword">-></span> <span class="cm-variable">u</span> <span class="cm-keyword">-></span> <span class="cm-variable">u</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">instance</span> <span class="cm-variable-2">Unit</span> <span class="cm-variable-2">Metre</span> <span class="cm-keyword">where</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> (<span class="cm-variable-2">M</span> <span class="cm-variable">x</span>) <span class="cm-error">‘</span><span class="cm-variable">plus‘</span> (<span class="cm-variable-2">M</span> <span class="cm-variable">y</span>) <span class="cm-keyword">=</span> <span class="cm-variable-2">M</span> (<span class="cm-variable">x</span><span class="cm-builtin">+</span><span class="cm-variable">y</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> (<span class="cm-variable-2">M</span> <span class="cm-variable">x</span>) <span class="cm-error">‘</span><span class="cm-variable">minus‘</span> (<span class="cm-variable-2">M</span> <span class="cm-variable">y</span>) <span class="cm-keyword">=</span> <span class="cm-variable-2">M</span> (<span class="cm-variable">x</span><span class="cm-builtin">-</span><span class="cm-variable">y</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">x</span> <span class="cm-error">‘</span><span class="cm-variable">ntimes‘</span> (<span class="cm-variable-2">M</span> <span class="cm-variable">y</span>) <span class="cm-keyword">=</span> <span class="cm-variable-2">M</span> (<span class="cm-variable">x</span><span class="cm-builtin">*</span><span class="cm-variable">y</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">instance</span> <span class="cm-variable-2">Unit</span> <span class="cm-variable-2">Yard</span> <span class="cm-keyword">where</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>(<span class="cm-variable-2">Yd</span> <span class="cm-variable">x</span>) <span class="cm-error">‘</span><span class="cm-variable">plus‘</span> (<span class="cm-variable-2">Yd</span> <span class="cm-variable">y</span>) <span class="cm-keyword">=</span> <span class="cm-variable-2">Yd</span> (<span class="cm-variable">x</span><span class="cm-builtin">+</span><span class="cm-variable">y</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">-- ...</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" class="cm-tab-wrap-hack" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- conversion</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">class</span> (<span class="cm-variable-2">Unit</span> <span class="cm-variable">u</span>) <span class="cm-keyword">=></span> <span class="cm-variable-2">Length</span> <span class="cm-variable">u</span> <span class="cm-keyword">where</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">toMetre</span> <span class="cm-keyword">::</span> <span class="cm-variable">u</span> <span class="cm-keyword">-></span> <span class="cm-variable-2">Metre</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">fromMetre</span> <span class="cm-keyword">::</span> <span class="cm-variable-2">Metre</span> <span class="cm-keyword">-></span> <span class="cm-variable">u</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">instance</span> <span class="cm-variable-2">Length</span> <span class="cm-variable-2">Metre</span> <span class="cm-keyword">where</span> </span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">toMetre</span> <span class="cm-keyword">=</span> <span class="cm-builtin">id</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">fromMetre</span> <span class="cm-keyword">=</span> <span class="cm-builtin">id</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">instance</span> <span class="cm-variable-2">Length</span> <span class="cm-variable-2">Yard</span> <span class="cm-keyword">where</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">toMetre</span> (<span class="cm-variable-2">Yd</span> <span class="cm-variable">x</span>) <span class="cm-keyword">=</span> <span class="cm-variable-2">M</span> (<span class="cm-variable">x</span><span class="cm-builtin">*</span><span class="cm-number">0.9144</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">fromMetre</span> (<span class="cm-variable-2">M</span> <span class="cm-variable">x</span>) <span class="cm-keyword">=</span> <span class="cm-variable-2">Yd</span> (<span class="cm-variable">x</span><span class="cm-builtin">/</span><span class="cm-number">0.9144</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; border-bottom: 0px solid transparent; top: 470px;"></div><div class="CodeMirror-gutters" style="display: none; height: 500px;"></div></div></div></pre><p> </p></div>
</body>
</html>