You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

713 lines
23 KiB

  1. \documentclass[10pt,a5paper,mathserif,serif,usenames,dvipsnames]{beamer}
  2. % packages
  3. \usepackage{xcolor}
  4. \usepackage[utf8]{inputenc}
  5. \usepackage{amsmath}
  6. \usepackage{amsfonts}
  7. \usepackage{amssymb}
  8. \usepackage{graphicx}
  9. \usepackage{listings}
  10. % for \verb inside \item
  11. \usepackage[T1]{fontenc}
  12. \usepackage[Q=yes]{examplep}
  13. % package configuration
  14. \DeclareGraphicsExtensions{.pdf,.png,.jpg}
  15. \beamertemplatenavigationsymbolsempty
  16. % title page information
  17. \author{Julian Ospald}
  18. \institute{FH Bielefeld}
  19. \title{Haskell: introduction}
  20. % color definition
  21. \definecolor{solarized}{HTML}{002B36}
  22. \definecolor{mygreen}{rgb}{0,0.6,0}
  23. % macros and environments
  24. \newcommand{\code}[1]{\texttt{#1}}
  25. \newcommand{\setHaskellCodeStyle}{
  26. \lstset{
  27. language=Haskell,
  28. backgroundcolor=\color{lightgray},
  29. commentstyle=\color{mygreen},
  30. keywordstyle=\color{blue},
  31. frame=single,
  32. keepspaces=true
  33. }
  34. }
  35. \newcommand{\setCCodeStyle}{
  36. \lstset{
  37. language=C,
  38. backgroundcolor=\color{lightgray},
  39. commentstyle=\color{mygreen},
  40. keywordstyle=\color{blue},
  41. frame=single,
  42. keepspaces=true
  43. }
  44. }
  45. \newcommand{\setCppCodeStyle}{
  46. \lstset{
  47. language=C++,
  48. backgroundcolor=\color{lightgray},
  49. commentstyle=\color{mygreen},
  50. keywordstyle=\color{blue},
  51. frame=single,
  52. keepspaces=true
  53. }
  54. }
  55. \begin{document}
  56. \frame{\titlepage}
  57. \begin{frame}
  58. \frametitle{Why haskell?}
  59. A Haskeller might claim: haskell...
  60. \begin{itemize}[<+->]
  61. \item eliminates certain classes of bugs
  62. \item not only disallows bad programs, but also defines what constitutes a bad program
  63. \item makes it easy to reason about code
  64. \item decreases the bus-factor
  65. \item makes it possible to apply huge changes to large programs without worrying about the implicit state machine
  66. \item makes it easier to program complex problems
  67. \item allows for clean APIs, even without any OOP
  68. \item a haskell program of 10K LOC isn't that much different to maintain as a 100K LOC
  69. \end{itemize}
  70. \vspace{\baselineskip}
  71. \onslide<+->
  72. We'll have to see if this holds true.
  73. \end{frame}
  74. \begin{frame}[fragile]
  75. \frametitle{Why haskell? (ctn.)}
  76. From C++ std:
  77. \setCppCodeStyle
  78. \begin{lstlisting}
  79. void pop();
  80. \end{lstlisting}
  81. \setCCodeStyle
  82. \onslide<+->
  83. From the C FLINT library:
  84. \begin{lstlisting}
  85. void fmpz_mod_poly_add(
  86. fmpz_mod_poly_t res,
  87. const fmpz_mod_poly_t poly1,
  88. const fmpz_mod_poly_t poly2);
  89. \end{lstlisting}
  90. \vspace{\baselineskip}
  91. \onslide<+->
  92. Regular C functions in real-world (omitting examples on purpose):
  93. \begin{itemize}[<+->]
  94. \item 100+ LOC
  95. \item at least 7 ifs, 4 whiles, 12 variables, 1 goto
  96. \item accesses both static and global variables
  97. \item indenting level of 5 or more
  98. \item a lot of memory management and custom-made error handling
  99. \item references everywhere!
  100. \end{itemize}
  101. \end{frame}
  102. \begin{frame}
  103. \frametitle{Why haskell? (ctn.)}
  104. You need to change only one single line in such a C function. You have to know:
  105. \begin{itemize}[<+->]
  106. \item does the order of function calls matter?
  107. \item how does the change effect the memory management? Do we have memory leaks? Do we access invalid memory?
  108. \item does it change the state of static or global variables?
  109. \item does it implicitly change the state of out-parameters?
  110. \item if it changes any of those states, is the function still correct?
  111. \item what happens if the program flow reaches this code-path with variable X in that particular state, while variable Z is NULL, and...
  112. \item did you just nuke a small former Soviet state?
  113. \end{itemize}
  114. \vspace{\baselineskip}
  115. \onslide<+->
  116. Conclusion: you really need to understand the complete environment of that line/function.
  117. \end{frame}
  118. \begin{frame}
  119. \frametitle{Why haskell? (ctn.)}
  120. But java helps! Does it?
  121. Sort of, because:
  122. \begin{itemize}[<+->]
  123. \item it improves APIs compared to C, since you can hide or encapsulate information in the state of an object
  124. \item it has a garbage collector, so you don't need to worry too much about memory
  125. \item an experienced programmer will find it easier to manage side-effects in Java, because you can e.g. have every impure functions throw an IO exception
  126. \end{itemize}
  127. \end{frame}
  128. \begin{frame}
  129. \frametitle{Why haskell? (ctn.)}
  130. Unfortunately, with java we:
  131. \begin{itemize}[<+->]
  132. \item now got even more states to keep track of (intellectual complexity?)
  133. \item have clouded the program flow... it's now about object-interaction with their explicit and implicit states and because of the increase of indirection, it might get even harder to do actual abstraction
  134. \item still have \textbf{side effects} everywhere: one object changes the state of another and vice versa, may arbitrarily write to the hard drive, do kernel calls or launch a missile
  135. \end{itemize}
  136. \onslide<+->
  137. Some parts of the implicit state machine have been made explicit by modelling classes, but it's still there and we have to deal with it, because we are modelling everything around states. Wouldn't it be nice if we could just forget about the global state machine? Maybe there is even a way to remove side effects and have more "predictability"?
  138. \onslide<+->
  139. \\
  140. \vspace{\baselineskip}
  141. We are lucky. There is. It's called \textbf{Haskell}.
  142. \end{frame}
  143. \begin{frame}
  144. \frametitle{What is haskell?}
  145. Haskell is a \textbf{functional}, \textbf{pure}, \textbf{lazy} and \textbf{statically typed} high-level programming language.\\
  146. \onslide<+->
  147. \vspace{\baselineskip}
  148. A few of the following facts will be white lies. But let's not worry about that. It's maybe more about "how to think in terms of haskell?" than "what is haskell?".
  149. \end{frame}
  150. \begin{frame}
  151. \frametitle{What does \textbf{functional} mean?}
  152. Think of haskell functions as regular \emph{mathematical} functions.
  153. \onslide<+->
  154. \vspace{\baselineskip}
  155. \includegraphics*[scale=0.4]{function-machine.png}
  156. \begin{itemize}[<+->]
  157. \item does this function write to the hard drive?
  158. \item does the output depend on anything else except the input (e.g. time, environment, ...)?
  159. \end{itemize}
  160. \onslide<+->
  161. \vspace{\baselineskip}
  162. It's all about \emph{input} and \emph{output} of functions! And that's it. Nothing else to worry about.
  163. \end{frame}
  164. \begin{frame}
  165. \frametitle{What does \textbf{functional} mean? (ctn.)}
  166. \begin{itemize}[<+->]
  167. \item \emph{first-class} citizens: functions are values and can be used as such
  168. \item a haskell program is what happens when \emph{expressions are evaluated}, it's not about executing instructions
  169. \end{itemize}
  170. \end{frame}
  171. \begin{frame}
  172. \frametitle{What does \textbf{pure} mean?}
  173. \emph{Referential transparency}, as in:
  174. \onslide<+->
  175. \begin{itemize}[<+->]
  176. \item everything (variables, data structures...) is \emph{immutable}
  177. \item expressions never have side-effects (remember: mathematical functions)
  178. \item same input $\mapsto$ same output... \emph{always}!
  179. \item replace a function with it's (return) value? Yes. What happens in C or java if you do that? Remember \code{void pop();}?
  180. \end{itemize}
  181. \onslide<+->
  182. \vspace{\baselineskip}
  183. possible benefits?
  184. \begin{itemize}[<+->]
  185. \item parallelism
  186. \item equational reasoning and refactoring
  187. \item less bugs!
  188. \end{itemize}
  189. \onslide<+->
  190. \vspace{\baselineskip}
  191. Question: call-by-value? call-by-reference? call-by-need?
  192. \end{frame}
  193. \begin{frame}
  194. \frametitle{What does \textbf{lazy} mean?}
  195. In haskell expressions are not evaluated until their results are actually needed. That has a lot of consequences, a few of them being:
  196. \onslide<+->
  197. \begin{itemize}[<+->]
  198. \item infinite data structures are now possible (recursive and non-recursive)
  199. \item defining new control structures by just defining a function (since not everything is evaluated... who needs if-then-else anyway?)
  200. \item important for compositional programming and efficiency
  201. \end{itemize}
  202. \end{frame}
  203. \begin{frame}
  204. \frametitle{What does \textbf{statically typed} mean?}
  205. Every haskell expression has a type and types are always checked at \emph{compile-time}. Programs with errors will not compile and definitely not run.\\
  206. \vspace{\baselineskip}
  207. It is possible to simulate dynamic types however. In the end, they are still statically type-checked (as in: the compiler always knows what's going on).
  208. \end{frame}
  209. \begin{frame}
  210. \frametitle{What is haskell again?}
  211. Let's reiterate. Haskell is:
  212. \begin{itemize}
  213. \item functional
  214. \item pure
  215. \item lazy
  216. \item statically typed (and truly type-safe)
  217. \item even garbage collected
  218. \item the world's finest imperative language (what??)
  219. \end{itemize}
  220. \end{frame}
  221. \begin{frame}
  222. \frametitle{Types, types, types}
  223. \begin{itemize}
  224. \item think in types!
  225. \item don't be afraid of type errors
  226. \item let the type-checker do the work for you (does this function do what I think it does?)
  227. \item understand functions just by looking at their type signature?
  228. \end{itemize}
  229. \end{frame}
  230. \begin{frame}[fragile]
  231. \frametitle{Declarations}
  232. Let's go!
  233. \setHaskellCodeStyle
  234. \begin{lstlisting}
  235. x :: Int
  236. x = 3
  237. -- how about this?
  238. x = 5
  239. -- Int vs Integer
  240. n :: Integer
  241. n = 12345678909876543219873409823349873498723498
  242. d :: Double
  243. d = 5.0
  244. c :: Char
  245. c = 'k'
  246. s :: String
  247. s = "Hello, world?"
  248. \end{lstlisting}
  249. \end{frame}
  250. \begin{frame}[fragile]
  251. \frametitle{Arithmetic and co.}
  252. \setHaskellCodeStyle
  253. GHCi:
  254. \begin{lstlisting}
  255. > 3 + 5
  256. > (3 :: Integer) + (5 :: Int)
  257. > 6 * 5.0
  258. > "Hello" ++ " world"
  259. > "Haskell" > "C++"
  260. > True && False
  261. \end{lstlisting}
  262. \end{frame}
  263. \begin{frame}[fragile]
  264. \frametitle{Functions and control structures}
  265. \setHaskellCodeStyle
  266. Let's make our first function. We want something like the following mathematical function\\
  267. $f(x) = x * x$\\
  268. \vspace{\baselineskip}
  269. How could the haskell code look like?
  270. \pause
  271. Almost the same:
  272. \begin{lstlisting}
  273. f x = x * x
  274. \end{lstlisting}
  275. \vspace{\baselineskip}
  276. GHCi...\\
  277. \pause
  278. \vspace{\baselineskip}
  279. What is a possible type signature for this function?
  280. \begin{lstlisting}
  281. f :: Int -> Int
  282. f x = x * x
  283. \end{lstlisting}
  284. So the function gets an Int and returns an Int. Don't get confused by "\verb|->|". Just think of it as a symbol for separating input and output.
  285. \end{frame}
  286. \begin{frame}[fragile]
  287. \frametitle{Functions and control structures (ctn.)}
  288. In haskell we often use \textbf{pattern matching}. That means we define a function multiple times, but e.g. for different values of its input arguments. Let's see:
  289. \pause
  290. \setHaskellCodeStyle
  291. \vspace{\baselineskip}
  292. \begin{lstlisting}
  293. isZero :: Int -> Bool
  294. isZero 0 = True
  295. isZero x = False
  296. \end{lstlisting}
  297. \vspace{\baselineskip}
  298. So if we pass it 0, we get True. If we do not pass 0, we get False and the value we passed gets basically ignored.\\
  299. \vspace{\baselineskip}
  300. What might happen if we remove the second or the third line? What is a \textbf{partial function} and a \textbf{total function}?
  301. \end{frame}
  302. \begin{frame}[fragile]
  303. \frametitle{Functions and control structures (ctn.)}
  304. How about \emph{recursion}? Let's define the modulo of any \emph{Int} to \emph{2}.
  305. \pause
  306. \setHaskellCodeStyle
  307. \vspace{\baselineskip}
  308. \begin{lstlisting}
  309. mod2 :: Int -> Int
  310. mod2 x
  311. | x - 2 == 0 = 0
  312. | x - 2 < 0 = x
  313. | otherwise = mod2 (x - 2)
  314. \end{lstlisting}
  315. These \verb#|# things above are called \textbf{guards} and are similar to \emph{pattern matching}. They are processed in order. If the condition on the left side of the equation is true, then it returns what stands on the right side of the equation. If it's false, then it processes the next line.\\ \code{otherwise} on the last line is just defined as \code{True}, to make these constructs easier to read and catch all other cases of input.
  316. \end{frame}
  317. \begin{frame}[fragile]
  318. \frametitle{Pairs/Tuples}
  319. Defining a pair is easy.
  320. \setHaskellCodeStyle
  321. \begin{lstlisting}
  322. p :: (Int, Char) -- this is the type
  323. p = (2, 'y') -- this is how we construct the pair
  324. -- pattern matching against pairs
  325. sumPair :: (Int, Int) -> Int
  326. sumPair (x, y) = x + y
  327. \end{lstlisting}
  328. \pause
  329. Note: we use \code{(x, y)} notation for both the type and the definition! Those are still two different things. We can also have triples, quadruples etc.
  330. \end{frame}
  331. \begin{frame}[fragile]
  332. \frametitle{Lists}
  333. \setHaskellCodeStyle
  334. The list is probably the most basic data structure in Haskell. Like the array in C. It is a singly-linked list and is very lazy. The compiler has numerous ways to optimize lists, so don't be afraid to use them, even for huge things.
  335. \pause
  336. We build lists by using either the \code{[]} notation:
  337. \begin{lstlisting}
  338. list1 :: [Integer]
  339. list1 = [1, 2]
  340. \end{lstlisting}
  341. \pause
  342. or by using the \emph{cons} operator \code{(:)} which takes an element and a list and produces a new list with the element prepended to the front.
  343. \begin{lstlisting}
  344. emptyList = []
  345. list2 = 1 : []
  346. -- is this really a list?
  347. list3 = [1, 2] == 1 : 2 : []
  348. \end{lstlisting}
  349. \pause
  350. How about something more interesting:
  351. \begin{lstlisting}
  352. infiniteList = [1..]
  353. \end{lstlisting}
  354. \end{frame}
  355. \begin{frame}[fragile]
  356. \frametitle{Lists (ctn.)}
  357. Let's check on a few very common list operations:
  358. \setHaskellCodeStyle
  359. \begin{lstlisting}
  360. > [1, 2] ++ [4, 5] -- append two lists
  361. > head [1, 2, 3] -- first element
  362. > tail [1, 2, 3] -- everything after the head
  363. > reverse [1, 2, 3] -- reverse a list
  364. > take 2 [1, 2, 3] -- take the first two elements
  365. > drop 2 [1, 2, 3] -- drop the first two elements
  366. > sum [1, 2, 3]
  367. > elem 7 [1, 2, 3] -- is there a 7 in the list?
  368. \end{lstlisting}
  369. \pause
  370. A String in haskell is just a list of Chars!
  371. \setHaskellCodeStyle
  372. \begin{lstlisting}
  373. > ['a', 'b', 'c']
  374. > 'a' : []
  375. > head "abc"
  376. > 'a' ++ 'c'
  377. \end{lstlisting}
  378. \end{frame}
  379. \begin{frame}[fragile]
  380. \frametitle{Lists (ctn.)}
  381. Again, we can do pattern matching on lists.
  382. \setHaskellCodeStyle
  383. \begin{lstlisting}
  384. listLen :: [Integer] -> Integer
  385. listLen [] = 0
  386. listLen (x:xs) = 1 + listLen xs
  387. \end{lstlisting}
  388. \pause
  389. We can also nest pattern matching:
  390. \begin{lstlisting}
  391. sumEveryTwo :: [Integer] -> [Integer]
  392. sumEveryTwo [] = 0
  393. sumEveryTwo (x:[]) = [x]
  394. sumEveryTwo (x:(y:zs)) = (x + y) : sumEveryTwo zs
  395. \end{lstlisting}
  396. Note that \code{(x:(y:zs))} may also be written as \code{(x:y:zs)}.
  397. \end{frame}
  398. \begin{frame}[fragile]
  399. \frametitle{Lists (ctn.)}
  400. Haskell also supports \textbf{list comprehension} which is basically syntactic sugar for what we already know from maths.\\
  401. Let's define a set that contains the first ten even natural numbers:\\
  402. \pause
  403. $S = \{2 \times x\ |\ x \in \mathbb{N},\ x \leq 10\}$\\
  404. \vspace{\baselineskip}
  405. \pause
  406. How does this look in haskell?
  407. \pause
  408. \setHaskellCodeStyle
  409. \begin{lstlisting}
  410. > [x*2 | x <- [1..10]]
  411. \end{lstlisting}
  412. \pause
  413. Now let's say we want all numbers between 50 and 100 that have the remainder 0 when divided by 12:
  414. \pause
  415. \setHaskellCodeStyle
  416. \begin{lstlisting}
  417. > [x | x <- [50..100], mod x 12 == 0]
  418. \end{lstlisting}
  419. \code{x <- [50..100]} is the binding, while \code{mod x 12 == 0} is the predicate, separated by a comma. We can have multiple predicates.
  420. \end{frame}
  421. \begin{frame}[fragile]
  422. \frametitle{Algebraic Data Types}
  423. Of course we can also define our own data types in haskell. One very common type is the \emph{enumeration}. For example, we could define a data type for the Week:
  424. \setHaskellCodeStyle
  425. \begin{lstlisting}
  426. data WeekDay = Monday
  427. | Tuesday
  428. | Thursday
  429. | Wednesday
  430. | Friday
  431. | Saturday
  432. | Sunday
  433. \end{lstlisting}
  434. This declares the new data type \code{WeekDay} with 7 \emph{constructors}. That means \code{Monday}, \code{Tuesday} etc. are all values of the type \code{WeekDay}.
  435. \pause
  436. \\
  437. We could now define a whole week, by creating a list:
  438. \pause
  439. \setHaskellCodeStyle
  440. \begin{lstlisting}
  441. week :: [WeekDay]
  442. week = [Monday, Tuesday, Thursday, Wednesday
  443. , Friday, Saturday, Sunday]
  444. \end{lstlisting}
  445. \end{frame}
  446. \begin{frame}[fragile]
  447. \frametitle{Algebraic Data Types (ctn.)}
  448. And we can again \emph{pattern match} on our \code{WeekDay} type. Let's find out if a given day is a Monday:
  449. \pause
  450. \setHaskellCodeStyle
  451. \begin{lstlisting}
  452. isMonday :: WeekDay -> Bool
  453. isMonday Monday = True
  454. isMonday x = False
  455. \end{lstlisting}
  456. \end{frame}
  457. \begin{frame}[fragile]
  458. \frametitle{Algebraic Data Types (ctn.)}
  459. But we can do more than enumerations. How about we do some error handling? Let's say we want a function to return an \code{Int}, but in case something went horribly wrong, we don't just want to return a 0 or some magic number, but a proper error message. Here we go:
  460. \pause
  461. \setHaskellCodeStyle
  462. \begin{lstlisting}
  463. data MaybeInt = NoError Int
  464. | Error String
  465. \end{lstlisting}
  466. \pause
  467. So constructors are just \emph{functions}! And they can have arguments, just like functions. Let's check their types:
  468. \setHaskellCodeStyle
  469. \begin{lstlisting}
  470. > :t NoError
  471. NoError :: Int -> MaybeInt
  472. > :t Error
  473. Error :: String -> MaybeInt
  474. \end{lstlisting}
  475. \pause
  476. And now we can do sanity checks:
  477. \setHaskellCodeStyle
  478. \begin{lstlisting}
  479. calcSomething :: Int -> MaybeInt
  480. calcSomething x
  481. | x < 100 = NoError (x * 5)
  482. | otherwise = Error "Int out of range!"
  483. \end{lstlisting}
  484. \end{frame}
  485. \begin{frame}[fragile]
  486. \frametitle{Algebraic Data Types (ctn.)}
  487. And pattern match on it as well:
  488. \setHaskellCodeStyle
  489. \begin{lstlisting}
  490. addIntToList :: MaybeInt -> [Int]
  491. addIntToList (NoError x) = [x]
  492. addIntToList (Error str) = []
  493. \end{lstlisting}
  494. So if we got an error, we just return an empty list, otherwise we return a list with the \code{Int} as its only element.
  495. \end{frame}
  496. \begin{frame}[fragile]
  497. \frametitle{Algebraic Data Types (ctn.)}
  498. Let's define something more complex. How about a tree?
  499. \pause
  500. \setHaskellCodeStyle
  501. \begin{lstlisting}
  502. data Tree = Leaf Char
  503. | Node Tree Int Tree
  504. \end{lstlisting}
  505. Uh... that looks mean. Let's examine this.\\
  506. \pause
  507. We have:
  508. \begin{itemize}[<+->]
  509. \item defined a data type \code{Tree}
  510. \item a constructor \code{Leaf} of type \code{Tree} with one arguments of type \code{Char}
  511. \item a constructor \code{Node} of type \code{Tree} with 3 arguments
  512. \begin{itemize}[<+->]
  513. \item \code{Tree}
  514. \item \code{Int}
  515. \item \code{Tree}
  516. \end{itemize}
  517. \end{itemize}
  518. \onslide<+->
  519. That means: a \code{Tree} can either be a \code{Leaf} or an internal \code{Node} with two sub-trees. If we want to create a \code{Leaf}, we have to pass the constructor a \code{Char}. If we want to create a \code{Node}, we have to pass 3 arguments, in order: another \code{Tree}, an \code{Int} and yet another \code{Tree}.\\
  520. So we can save information in the leafs (\code{Char}) and in the internal nodes (\code{Int}).\\
  521. This is just an example. There are endless more ways of trees.
  522. \end{frame}
  523. \begin{frame}[fragile]
  524. \frametitle{Algebraic Data Types (ctn.)}
  525. Let's build our tree:
  526. \setHaskellCodeStyle
  527. \begin{lstlisting}
  528. tree :: Tree
  529. tree = Node
  530. (Leaf 'x')
  531. 1
  532. (Node
  533. (Leaf 'y')
  534. 2
  535. (Leaf 'z')
  536. )
  537. \end{lstlisting}
  538. See board...
  539. \end{frame}
  540. \begin{frame}[fragile]
  541. \frametitle{Algebraic Data Types (ctn.)}
  542. So if we want to generalize it, an algebraic data type has one or more \textbf{constructors}, and each of them can have zero or more arguments. E.g.:
  543. \setHaskellCodeStyle
  544. \begin{lstlisting}
  545. data AlgDataType = Constr1 Type11 Type12
  546. | Constr2 Type21
  547. | Constr3 Type31 Type32 Type33
  548. | Constr4
  549. \end{lstlisting}
  550. \end{frame}
  551. \begin{frame}
  552. \frametitle{Questions?}
  553. \begin{itemize}
  554. \item How do functions with multiple parameters look like?
  555. \item ...
  556. \end{itemize}
  557. \end{frame}
  558. \begin{frame}
  559. \frametitle{Common misconceptions}
  560. Now that we know the basics, let's clear up some common misconceptions about haskell.
  561. \begin{itemize}[<+->]
  562. \item haskell is only a language for university professors
  563. \item haskell is not used in real world, see \url{https://wiki.haskell.org/Haskell_in_industry}
  564. \begin{itemize}
  565. \item Microsoft
  566. \item NVIDIA
  567. \item facebook
  568. \item Google
  569. \item Intel
  570. \item AT\Q{&}T
  571. \end{itemize}
  572. \item you cannot model states in haskell
  573. \item you cannot write larger programs in haskell
  574. \item you cannot write useful programs in haskell
  575. \item you cannot implement imperative algorithms
  576. \item you cannot do concurrency, cryptography, web development, ... in haskell
  577. \end{itemize}
  578. \onslide<+->
  579. You can!
  580. \end{frame}
  581. \begin{frame}
  582. \frametitle{Difficulties}
  583. Haskell is very powerful and can be used for pretty much anything. However, there are difficulties in any language. Let's name a few for haskell:
  584. \begin{itemize}[<+->]
  585. \item intellectual complexity? New way of thinking?
  586. \item although you rarely need it in haskell, debugging can be difficult at times
  587. \item because the type system is extremely powerful/complex, type error messages can be very confusing and don't always show the error you expected
  588. \item no premium-like IDE with every possible feature (yet)
  589. \item dynamic linking is sort of WIP yet, lots of ABI breakage
  590. \item because most of the world thinks in imperative style languages, it's often difficult to find pseudo-code for functional style languages, so you end up reverse-engineering algorithms
  591. \item some problems that are trivial in imperative languages, can be very difficult to solve in idiomatic haskell and vice versa
  592. \item practical cryptography is possible, but a difficult topic in haskell, see \url{https://mail.haskell.org/pipermail/haskell-cafe/2015-February/118059.html}
  593. \end{itemize}
  594. \end{frame}
  595. \begin{frame}
  596. \frametitle{Toolchain}
  597. How to get started? You need:
  598. \begin{itemize}
  599. \item \textbf{GHC}: this is the Haskell compiler
  600. \item \textbf{GHCi}: this an interactive environment of GHC, similar to the interactive ruby shell \emph{irb}
  601. \item \textbf{The Haskell Platform}: a collection including GHC, GHCi and basic libraries
  602. \end{itemize}
  603. Go to \url{https://www.haskell.org/platform}\\
  604. For haskell IDEs, see \url{https://wiki.haskell.org/IDEs}
  605. \end{frame}
  606. \begin{frame}
  607. \frametitle{Further reading and useful links}
  608. \begin{itemize}
  609. \item the most popular haskell course from Brent Yorgey:\\ \url{https://www.seas.upenn.edu/~cis194/fall14/spring13/lectures.html}
  610. \item very verbose and enthusiastic haskell book, good for reading once:\\ \url{http://learnyouahaskell.com}
  611. \item collection of websites teaching haskell:\\ \url{https://github.com/bitemyapp/learnhaskell}
  612. \item haskell programming tips (and wiki):\\ \url{https://wiki.haskell.org/Haskell_programming_tips}
  613. \item the standard module (similar to libc in C):\\ \url{https://hackage.haskell.org/package/base-4.7.0.0/docs/Prelude.html}
  614. \item debugging in haskell:\\ \url{https://wiki.haskell.org/Debugging}
  615. \end{itemize}
  616. \end{frame}
  617. \begin{frame}
  618. \frametitle{What you should know now}
  619. \begin{itemize}
  620. \item what haskell is
  621. \item how you write haskell functions
  622. \item how you handle lists and pairs
  623. \item how you do pattern matching
  624. \item how you create your own data types
  625. \end{itemize}
  626. \end{frame}
  627. \begin{frame}[fragile]
  628. \frametitle{You should be able to answer these questions}
  629. \begin{itemize}
  630. \item What are side effects?
  631. \item What is referential transparency?
  632. \item Can you have referential transparency with side effects?
  633. \item What does the output of a haskell function depend on?
  634. \item What is laziness?
  635. \item When are types checked in haskell?
  636. \end{itemize}
  637. \vspace{\baselineskip}
  638. Does this compile? If not, fix it. Is this a total function?
  639. \setHaskellCodeStyle
  640. \begin{lstlisting}
  641. data FakeInt = MkDouble Double
  642. | MkInt Int
  643. f :: Int -> FakeInt
  644. f 0 = 0.5
  645. \end{lstlisting}
  646. \end{frame}
  647. \begin{frame}
  648. \frametitle{Sources}
  649. \begin{itemize}
  650. \item much content was borrowed or is based on the haskell course from Brent Yorgey:\\ \url{https://www.seas.upenn.edu/~cis194/fall14/spring13/lectures.html}
  651. \item a few small pieces from the LYAH book \url{http://learnyouahaskell.com}
  652. \item general information from wikipedia: \\ \url{https://en.wikipedia.org}
  653. \item general information from haskell wiki: \\ \url{https://wiki.haskell.org}
  654. \end{itemize}
  655. \end{frame}
  656. \end{document}