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.
 
 
 

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