aboutsummaryrefslogtreecommitdiff
path: root/cloogle.tex
blob: 09ded12c5505dd08f98f79b25bcf97da7a762c3f (plain) (blame)
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
\documentclass{beamer}

\let\oldhref\href
\def\href#1#2{\oldhref{#1}{\color{cloogledark!50!clooglemain} #2}}
\def\https#1{\href{https://#1}{#1}}
\def\mailto#1{\href{mailto:#1}{#1}}

\title[Cloogle]{\texorpdfstring{\includegraphics[width=5em]{logo}}{Cloogle}}
\subtitle{A programming language search engine and its applications}
\author[Camil Staps]{\texorpdfstring{Camil Staps\\[1em]\footnotesize\mailto{camil@cloogle.org}}{Camil Staps}}
\date{January 5\textsuperscript{th}, 2018}

\usetheme{CambridgeUS}
\usecolortheme{cloogle}
\useinnertheme{circles}
\setbeamertemplate{itemize item}[triangle]
\setbeamertemplate{itemize subitem}[circle]

\usepackage[british]{babel}
\usepackage{csquotes}

\usepackage{tikz}
\usepackage{clooglearch}

\usepackage{minted}
\setminted{fontsize=\small}

% https://tex.stackexchange.com/a/23522/23992
\def\imagetop#1{\vtop{\null\hbox{#1}}}

\AtBeginSubsection[]{%
	\begin{frame}
		\frametitle{Table of Contents}
		\tableofcontents[currentsection,currentsubsection]
	\end{frame}}

\begin{document}

\maketitle

\section{Background}
\subsection{Why build a search engine?}
\begin{frame}[fragile]{Background}
	\begin{itemize}[<+->]
		\item
			What is wrong with this code?

			\begin{minted}[gobble=4]{clean}
				incAll :: [Int] -> [Int]
				incAll []     = []
				incAll [x:xs] = [x+1:incAll xs]
			\end{minted}

		\item
			Better:
			\begin{minted}[gobble=4]{clean}
				incAll = map ((+) 1)
			\end{minted}
	\end{itemize}
\end{frame}
\begin{frame}{Background}
	Lack of abstraction due to...

	\begin{itemize}
		\item Poor conceptualisation of the programmer?
		\pause
		\item Poor knowledge of the standard libraries?

			\medskip
			\quad\enquote{There is this function \texttt{map}, but where is it defined?}
	\end{itemize}

	\pause
	Solution: build a search engine!
\end{frame}

\section{Functionality}
\subsection{Overview}
\begin{frame}{Functionality}
	\centering
	\begin{tabular}{l l}
		\imagetop{\includegraphics[width=.45\textwidth]{scrot-search-name}} & \pause
		\imagetop{\includegraphics[width=.45\textwidth]{scrot-search-unify}} \pause\\
		\imagetop{\includegraphics[width=.45\textwidth]{scrot-search-typedef}} \pause&
		\imagetop{\includegraphics[width=.45\textwidth]{scrot-search-class}}
	\end{tabular}
\end{frame}

\subsection{Efficient unification search}
\begin{frame}{Efficient unification search}
	\begin{itemize}[<+->]
		\item With $\pm15,000$ functions, brute force unification search takes too long
		\item Grouping types together still gives $\pm13,000$ unique types
		\item If type $t$ generalises $u$, any $v$ that unifies with $u$ will also unify with $t$
			\begin{itemize}
				\item Conversely, if $v$ does not unify with $t$ it will not unify with $u$
			\end{itemize}
		\item This gives a partial order on types:

			\begin{center}
				\begin{tikzpicture}[level distance=2em]
					\tikzstyle{level 1}=[sibling distance=14em]
					\tikzstyle{level 2}=[sibling distance=7em]
					\tikzstyle{level 3}=[sibling distance=2em]
					\node {$a$}
						child {node {$a \rightarrow b$}
							child {node {$Int \rightarrow m~a$} child {node {\vdots}}}
							child {node {$a~a \rightarrow a$} child {node {\vdots}} child {node {\vdots}}}}
						child {node {$f~Real$}
							child {node {$Maybe~Real$}}
							child {node {$Either~a~Real$} child {node {\vdots}}}};
				\end{tikzpicture}
			\end{center}

		\item Early pruning speeds up unification search with a factor of $2-3$!
	\end{itemize}
\end{frame}

\begin{frame}[shrink]{Efficient unification search}
	\begin{itemize}[<+->]
		\item I would show the full tree, but didn't find a viewer that wouldn't crash
		\item Here is a detail of the tree for 5,000 functions:

			\medskip
			\begin{center}
				\includegraphics[width=\textwidth]{typetree-detail}
			\end{center}
	\end{itemize}
\end{frame}

\section{Architecture}
\subsection{Overview}
\begin{frame}{Architecture}
	\centering
	\footnotesize
	\begin{tikzpicture}[every node/.style={draw,block}]
		\useasboundingbox (-5,-4) rectangle (3.5,4);
		\only<1->\tikzsource
		\only<2->\tikzbuilddb
		\only<3->\tikzbackend
		\only<4->\tikzcache
		\only<5->\tikzfrontend
		\only<6->\tikzfrontendsrc
		\only<7->\tikzstats
		\only<8->\tikzclientA
		\only<9->\tikzclientB
		\only<10->\tikzclientC
		\only<11->\tikzclientD
		\only<12->\tikzclientE
	\end{tikzpicture}
\end{frame}

\subsection{Running locally: cloogle-tags}
\begin{frame}[fragile]{What if we want to run Cloogle locally?}
	\begin{itemize}
		\item Most common use case: finding definitions in personal libraries
		\pause
		\item Many editors support \emph{tagfiles}:

			\begin{minted}[gobble=4]{text}
				drop    StdList.dcl    46
				fopen   StdFile.dcl    27
				...
			\end{minted}
	\end{itemize}
\end{frame}
\begin{frame}{Running locally: old architecture}
	\centering
	\footnotesize
	\begin{tikzpicture}[every node/.style={draw,block}]
		\useasboundingbox (-5,-4) rectangle (3.5,4);
		\tikzsource
		\tikzbuilddb
		\tikzbackend
		\tikzcache
		\tikzfrontend
		\tikzfrontendsrc
		\tikzstats
		\tikzclientA
		\tikzclientB
		\tikzclientC
		\tikzclientD
		\tikzclientE
	\end{tikzpicture}
\end{frame}
\begin{frame}{Running locally: new architecture}
	\centering
	\footnotesize
	\begin{tikzpicture}[every node/.style={draw,block}]
		\useasboundingbox (-5,-4) rectangle (3.5,4);
		\tikzsource
		\tikzbuilddb
		\only<1>{%
			\tikzbackend[1]
			\tikzcache[1]
			\tikzfrontend[1]
			\tikzfrontendsrc[1]
			\tikzstats[1]
			\tikzclientA
			\tikzclientB
			\tikzclientC
			\tikzclientD
			\tikzclientE}
		\only<2->{%
			\tikzbackend[2]
			\tikzcache[2]
			\tikzfrontend[2]
			\tikzfrontendsrc[2]
			\tikzstats[2]
			\tikzclientB[2]
			\tikzclientC[2]
			\tikzclientD[2]
			\tikzclientE[2]
			\tikzcloogletags}
		\only<2>{\tikzclientA[2]}
		\only<3>{\tikzclientA[3]}
		\only<4>{\tikzclientA[4]}
	\end{tikzpicture}
\end{frame}

\section*{The end}

\subsection*{Discussion}
\begin{frame}[fragile]{Discussion}
	\begin{itemize}[<+->]
		\item The first generation of students was very enthusiastic
			\begin{itemize}
				\item The second not so much...
				\item But statistics show they used it more and more during the course
			\end{itemize}

		\item Unification search has some issues: you will never find

			\begin{minted}[gobble=4]{clean}
				fopen :: String Int *f -> (Bool, *File, *f)
			\end{minted}

			\begin{itemize}
				\item But a unifier gives useful information, like required instances
				\item Unification allows for optimisations that a distance measure does not
			\end{itemize}

		\item It's not just about search: indexing code has many use cases!

			\begin{itemize}
				\item Jumping to definitions (tagfiles)
				\item Automatic imports (vim-clean)
				\item Type-based code completion?
			\end{itemize}
	\end{itemize}
\end{frame}

\subsection*{Acknowledgements}
\begin{frame}[shrink]{Acknowledgements}
	Cloogle was conceived and built by:

	\begin{itemize}
		\item Camil Staps
		\item Mart Lubbers
	\end{itemize}

	With contributions by:

	\begin{itemize}
		\item Erin van der Veen
		\item Koen Dercksen
	\end{itemize}

	Using:

	\begin{itemize}
		\item The Clean compiler (the Clean team)
	\end{itemize}

	With thanks to:

	\begin{itemize}
		\item All users, for new ideas and bug reports (explicitly or in the query log)
	\end{itemize}

	Authors of clients:

	\begin{itemize}
		\item CLI app: Koen Dercksen
		\item IRC bot: Mart Lubbers
		\item vim-clean integration, Telegram bot, email client: Camil Staps
		\item Visual Studio Code plugin: Lucas Franceschino
	\end{itemize}
\end{frame}

\appendix
\AtBeginSubsection[]{}
\newcounter{finalframe}
\setcounter{finalframe}{\value{framenumber}}

\section{Appendices}

\begin{frame}
	\frametitle{Appendices}
	\tableofcontents[currentsection]
\end{frame}

\subsection{Can I use Cloogle for language X?}
\begin{frame}{Can I use Cloogle for language X?}
	\begin{itemize}
		\item It will work best on a language with the Hindley-Milner type system
			\begin{itemize}
				\item It can still be useful to less strongly typed languages
				\item It would be interesting to develop a search engine for dependent types
			\end{itemize}
		\item The search system is language-agnostic, but you need a tool to index source code into our JSON format
		\item Also see: \https{neilmitchell.blogspot.nl/2011/03/hoogle-for-your-language-ie-f-scala-ml.html}
		\item Contact me!
	\end{itemize}
\end{frame}

\subsection{Numbers}
\begin{frame}{Numbers\setcounter{footnote}{0}\footnotemark}
	\setcounter{footnote}{1}
	\begin{columns}[t]
		\begin{column}{.5\textwidth}
			\begin{itemize}
				\item Database

					\begin{description}[Syntax constructs]
						\small
						\item[Modules] 750
						\item[Functions] 15,297
						\item[Unique types] 13,571
						\item[Type tree depth] 8
						\item[Type definitions] 2,195
						\item[Classes] 262
						\item[Instances] 1958
						\item[Derivations] 1,182
						\item[Syntax constructs] 35
					\end{description}
			\end{itemize}
		\end{column}
		\begin{column}{.5\textwidth}
			\begin{itemize}
				\item Lines of code\footnotemark
					% cloc --exclude-dir=clean-compiler,CleanRep.2.2_files,CleanRep.2.2.css,storage,cache,Clean\ System\ Files,types.json,typetree.dot,cloogle.log,tags .

					\begin{description}[Bourne Shell]
						\small
						\item[Clean] 4,739
						\item[JavaScript] 1,657
						\item[PHP] 831
						\item[HTML] 569
						\item[CSS] 406
						\item[Python] 110
						\item[Bourne Shell] 71
					\end{description}
			\end{itemize}
		\end{column}
	\end{columns}

	\medskip
	\begin{itemize}
		\item Visitor statistics: \https{cloogle.org/stats/longterm.html}
	\end{itemize}

	\setcounter{footnote}{1}
	\footnotetext{2017-10-28}
	\setcounter{footnote}{2}
	\footnotetext{On the web frontend and submodules, excluding the Clean compiler}
\end{frame}

\subsection{Links}
\begin{frame}[shrink]{Links}
	\footnotesize
	\textbf{Core system:}
	\begin{description}[VS Code plugin]
		\item[API] \https{github.com/clean-cloogle/libcloogle}
		\item[Core] \https{github.com/clean-cloogle/Cloogle}
		\item[Web] \https{github.com/clean-cloogle/cloogle.org}
		\item[JS highlighter] \https{github.com/clean-cloogle/clean.js}
		\item[Pygments lexer] \https{github.com/clean-cloogle/pygments-lexer-clean}
		\item[Pretty printer] \https{github.com/clean-cloogle/CleanPrettyPrint}
		\item[Type unifier] \https{github.com/clean-cloogle/CleanTypeUnifier}
	\end{description}

	\textbf{Clients:}
	\begin{description}[VS Code plugin]
		\item[vim-clean] \https{github.com/camilstaps/vim-clean}
		\item[CLI app] \https{github.com/clean-cloogle/cloogle-cli}
		\item[Telegram bot] \https{telegram.me/CloogleBot}; \https{github.com/clean-cloogle/CloogleBot}
		\item[IRC bot] \#cloogle on \https{freenode.net}; \https{github.com/clean-cloogle/clean-irc}
		\item[Email client] \mailto{query@cloogle.org}; \https{github.com/clean-cloogle/cloogle-mail}
		\item[VS Code plugin] \https{github.com/W95Psp/CleanForVSCode}
	\end{description}

	\textbf{Miscellaneous:}
	\begin{description}[Pygments lexer]
		\item[cloogle-tags] \https{github.com/clean-cloogle/cloogle-tags}
		\item[These slides] \https{github.com/clean-cloogle/presentation-NL-FP-2018}
	\end{description}
\end{frame}

\setcounter{framenumber}{\value{finalframe}}

\end{document}