-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhaskelltut1.html
249 lines (224 loc) · 11 KB
/
haskelltut1.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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2022-06-02 Thu 20:55 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>‎</title>
<meta name="generator" content="Org Mode" />
<link rel="stylesheet" href="./tufte.css" type="text/css">
</head>
<body>
<div id="content" class="content">
<div class="header">
<link rel="stylesheet" href="hamb.css">
<link rel="stylesheet" href="tufte.css">
<img src="./images/heading6.png" style="padding: 0px 0px 22px 0px" alt="3-d graph" class="center">
<p>
<nav role="navigation">
<div id="menuToggle">
<!--
A fake / hidden checkbox is used as click reciever,
so you can use the :checked selector on it.
-->
<input type="checkbox" />
<!--
Some spans to act as a hamburger.
They are acting like a real hamburger,
not that McDonalds stuff.
-->
<span></span>
<span></span>
<span></span>
<!--
Too bad the menu has to be inside of the button
but hey, it's pure CSS magic.
-->
<ul id="menu">
<a href="index.html" target="_blank"><li>Home</li></a>
<a href="preface.html" target="_blank"><li>Preface</li></a>
<a href="preliminaries.html" target="_blank"><li>Rabbit Holes</li></a>
<a href="numbers.html" target="_blank"><li>Numbers</li></a>
</ul>
</div>
</nav>
</div>
</p>
<div id="outline-container-org932f40a" class="outline-2">
<h2 id="org932f40a">Haskell tutorial 1</h2>
<div class="outline-text-2" id="text-org932f40a">
<p>
<label for="mn-demo" class="margin-toggle"></label>
<input type="checkbox" id="mn-demo" class="margin-toggle">
<span class="marginnote">
<img src="images/HaskellCurrySign.jpg" alt="HaskellCurrySign.jpg" />
</span>
</p>
</div>
</div>
<div id="outline-container-orgcca06c4" class="outline-2">
<h2 id="orgcca06c4">Rabbit holes</h2>
<div class="outline-text-2" id="text-orgcca06c4">
<p>
Let’s repeat (most of) the Haskell rabbit hole list
</p>
<p>
<font color = "#375e79">
⌜🐇
</p>
<ol class="org-ol">
<li><a href="http://learnyouahaskell.com/chapters">Learn You a Haskell for Great Good!</a> (LYAHFGG) is a widely-used,
often-suggested beginners site for starting out with Haskell. Work
through at least chapters 1 and 2 to understand a lot of what we’ll
be doing with Haskell below. (<i>R<sub>C</sub>-hole</i>)</li>
<li>A site haskell.org is suggesting is the UPenn course CIS194. We
suggest the <a href="https://www.seas.upenn.edu/~cis194/spring15/">Spring 2015</a> version since it includes haskell source
files. This is a college course, but for beginners. Click on the
<i>Lectures & Assignments</i> link at the top. (If you’ve got <a href="https://github.com/borgauf/omnimath">our github
repository</a> there’s a directory containing all the Haskell files.)
(<i>R<sub>O</sub>-hole</i>)</li>
<li>An older but still go-to site recommended by many is the <i><a href="http://book.realworldhaskell.org/read/">Real
World Haskell</a></i> site (also book). As the title suggests, it has a
more real-applications slant, and yes, the material can get into
heavy lifting, but one great advantage is it has prodigious
<i>comments</i> attached to ever web page section. So if you didn’t
understand something, typically somebody has already explained it
in depth.</li>
<li>Book-wise, a nice, well-paced text would be <i><a href="https://www.manning.com/books/get-programming-with-haskell#:~:text=about%20the%20book,dive%20into%20custom%20Haskell%20modules.">Get Programming with
Haskell</a></i> by Will Kurt. Will bridges a lot of chasms between
beginner, intermediary, and advanced ideas. In other words, GPWH
gives plain-English explanations of things other treatments might go
deep into theory on. Really helpful, that. (<i>R<sub>O</sub>-hole</i>)</li>
<li>Another big favorite for Haskell starters, but slightly more
challenging is <i><a href="https://www.haskell.org/tutorial/haskell-98-tutorial.pdf">A Gentle Introduction to Haskell 98</a></i>. AGITH uses
more math terminology, which is what we’re doing, but from the
shallow end first. (<i>R<sub>O</sub>-hole</i>)</li>
<li>A while back the programming language Prolog created a list of
ninety-nine sample problems that were solved using Prolog. Since
then many languages have cooked up their own versions of answering
the ninety-nine. Haskell’s is <a href="https://wiki.haskell.org/H-99:_Ninety-Nine_Haskell_Problems">here</a>. We’ll refer to this a
lot. When you peek at the solutions, don’t get psyched out by some
of the answers. Haskell Wiki is a volunteer site and very smart
people like show off their skills resulting in some serious
overkill. Just make sure you can handle the basic answers, and
maybe peruse the wilder versions. (<i>R<sub>O</sub>-hole</i>)</li>
</ol>
<p>
</font>🐇⌟
</p>
</div>
</div>
<div id="outline-container-org6cc1905" class="outline-2">
<h2 id="org6cc1905">Setting up Haskell</h2>
<div class="outline-text-2" id="text-org6cc1905">
<p>
We will use <a href="https://docs.haskellstack.org/en/stable/README/">The Haskell Tool Stack</a>, which is a project/package
management system for Haskell. In a nutshell, we will install
stack—and then use stack to set up custom Haskell programming
environments on a project-by-project basis. Besides the executable
<code>stack</code>, there will also be the Haskell compiler <code>ghc</code> and the Haskell
interactive mode <code>ghci</code> which are called as stack arguments <br />
<code>> stack ghci</code> <br />
<code>> stack ghc</code> <br />
More on using them shortly.
</p>
<p>
This guide will go into detail only on the Linux Haskell install. For
full details (also for other OS types) see <a href="https://docs.haskellstack.org/en/stable/install_and_upgrade/">The Haskell Tool Stack</a>.
</p>
<ul class="org-ul">
<li>The very first step might not be needed, but we’ll do it just to
make sure. Haskell requires (and recommends) a set of Linux system
programs and libraries. Run this at the command line (all on one
line)</li>
<li><code>> sudo apt-get install g++ gcc libc6-dev libffi-dev libgmp-dev make
xz-utils zlib1g-dev git gnupg netbase curl</code> <br />
Typically all of these (with the exception of curl) are already on
board and won’t be updated.</li>
<li>To install stack run <br />
<code>> curl -sSL https://get.haskellstack.org/ | sh</code> <br />
This will ask for your password; enter it to allow system-wide
install.</li>
<li>Now you should have Haskell stack on your system. For confirmation
of success run <br />
<code>> which stack</code> <br />
This should return <br />
<code>/usr/local/bin/stack</code> <br />
or wherever the <code>stack</code> executable was installed.</li>
<li>Now, run <br />
<code>> echo 'PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc</code> <br />
This tells your shell environment<label for="1" class="margin-toggle sidenote-number"></label><input type="checkbox" id="1" class="margin-toggle"/><span class="sidenote">
Another name for terminal or command line is <i>shell</i>. Each
terminal you start with a command line interface is a <i>shell</i> with a
<i>shell environment</i>. The <code>.bashrc</code> file is its configuration file that
is read and set up each time you start another terminal command line
instance. In our situation we have to let the environment know where
the new Haskell stuff has been installed.
</span> about this new location
where some of Haskell executables might be later on if we choose to
install them. We’re not now, but it’s good to have this ahead of
time. Kill your terminal, restart it, then check with <br />
<code>> echo $PATH</code> <br />
You should see something like <br />
<code>> /home/myhomedir/.local/bin:/usr/local/sbin:/usr/local/bin:...</code> <br />
…and many others possibly. But we see our
<code>/home/myhomedir/.local/bin</code>. Good.</li>
</ul>
<p>
Again, stack is project-oriented, but for the time being we only want
to use the Haskell REPL loading the code we saved into <code>*.hs</code>
files. Still, this will take place inside a project we set up with
stack. Eventually, we’ll convert from using <code>hs</code> files to using Emacs’
powerful <i>org-mode literate programming</i> with the REPL.
</p>
<ul class="org-ul">
<li>In your top home directory<label for="2" class="margin-toggle sidenote-number"></label><input type="checkbox" id="2" class="margin-toggle"/><span class="sidenote">
You can always get back home by typing <code>cd</code> and Enter. Then do
<code>pwd</code> to confirm you’ve gone to top home. And you can always test
where you are with <code>> pwd</code> (present working directory).
</span> create an org directory <br />
<code>> mkdir org</code> <br />
and <code>cd</code> into it <br />
<code>> cd org</code></li>
<li>Now we will create a project, which will create a new directory
under <code>~/org/</code>. Type <br />
<code>> stack new haskellwork1</code> <br />
which will set up a project in a subdirectory of <code>org</code> called
<code>haskellwork1</code>.</li>
<li><code>cd</code> into <code>haskellwork1</code> and do <code>ls</code> to get a file listing. You’ll
see new files and directories newly created.</li>
<li>Still in the <code>haskellwork1</code> directory type
<code>> stack setup</code> <br />
which should give a short message about using a sandboxed GHC etc.</li>
<li>Next, type
<code>> stack build</code> <br />
which will run through a build procedure and return you the prompt.</li>
<li>To test
<code>> stack exec haskellwork1-exe</code> <br />
which will return <code>someFucn</code>, i.e., the output of the dummy starter
code the project created.</li>
</ul>
<p>
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank"><img src="./images/by-nc-sa.png" width="125px" style="padding: 100px 0px 0px 0px" alt="License-disense" class="center"></a>
</p>
</div>
</div>
<!-- Footnotes --><!--
<div class="footdef"><sup><a id="fn.1" class="footnum" href="#fnr.1" role="doc-backlink">1</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">
Another name for terminal or command line is <i>shell</i>. Each
terminal you start with a command line interface is a <i>shell</i> with a
<i>shell environment</i>. The <code>.bashrc</code> file is its configuration file that
is read and set up each time you start another terminal command line
instance. In our situation we have to let the environment know where
the new Haskell stuff has been installed.
</p></div></div>
<div class="footdef"><sup><a id="fn.2" class="footnum" href="#fnr.2" role="doc-backlink">2</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">
You can always get back home by typing <code>cd</code> and Enter. Then do
<code>pwd</code> to confirm you’ve gone to top home. And you can always test
where you are with <code>> pwd</code> (present working directory).
</p></div></div>
--></div>
</body>
</html>