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.
 
 
 

138 lines
4.5 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. % package configuration
  11. \DeclareGraphicsExtensions{.pdf,.png,.jpg}
  12. % title page information
  13. \author{Julian Ospald}
  14. \institute{FH Bielefeld}
  15. \title{Haskell: introduction}
  16. % color definition
  17. \definecolor{solarized}{HTML}{002B36}
  18. \begin{document}
  19. % page 0
  20. \frame{\titlepage}
  21. % page 1
  22. \begin{frame}
  23. \frametitle{Why haskell?}
  24. A Haskeller might claim: haskell...
  25. \begin{itemize}
  26. \item eliminates certain classes of bugs
  27. \item makes it easy to reason about code
  28. \item decreases the bus-factor
  29. \item makes it possible to apply huge changes to large programs without worrying about the implicit state machine
  30. \item makes it easier to program complex problems
  31. \item allows for clean APIs, even without any OOP
  32. \item a haskell program of 10K LOC isn't that much different to maintain as a 100K LOC
  33. \end{itemize}
  34. \vspace{\baselineskip}
  35. We'll have to see if this holds true.
  36. \end{frame}
  37. % page 1
  38. \begin{frame}[fragile]
  39. \frametitle{Why haskell? (ctn.)}
  40. From C++ std:
  41. \lstset{
  42. language=C++,
  43. backgroundcolor=\color{White},
  44. frame=single,
  45. keepspaces=true
  46. }
  47. \begin{lstlisting}
  48. void pop();
  49. \end{lstlisting}
  50. \lstset{
  51. language=C,
  52. }
  53. From the C FLINT library:
  54. \begin{lstlisting}
  55. void fmpz_mod_poly_add(
  56. fmpz_mod_poly_t res,
  57. const fmpz_mod_poly_t poly1,
  58. const fmpz_mod_poly_t poly2);
  59. \end{lstlisting}
  60. \vspace{\baselineskip}
  61. Regular C functions in real-world (omitting examples on purpose):
  62. \begin{itemize}
  63. \item 100+ LOC
  64. \item at least 7 ifs, 4 whiles, 12 variables, 1 goto
  65. \item access both static and global variables
  66. \item indenting level of 5 or more
  67. \item a lot of memory management and custom-made error handling
  68. \end{itemize}
  69. \end{frame}
  70. \begin{frame}
  71. \frametitle{Why haskell? (ctn.)}
  72. You need to change only one single line in such a C function. You have to know:
  73. \begin{itemize}
  74. \item does the order of function calls matter?
  75. \item how does the change effect the memory management? Do we have memory leaks? Do we access invalid memory?
  76. \item does it change the state of static or global variables?
  77. \item does it implicitly change the state of out-parameters?
  78. \item if it changes any of those states, is the function still correct?
  79. \item does the program flow break? Do we have unreachable codepaths now?
  80. \item did you just nuke a small former Soviet state?
  81. \end{itemize}
  82. \end{frame}
  83. \begin{frame}
  84. \frametitle{Why haskell? (ctn.)}
  85. But java helps! Does it?
  86. Sort of, because:
  87. \begin{itemize}
  88. \item it improves APIs compared to C, since you can hide information in the state of an object (but... it's hidden now)
  89. \item it has a garbage collector, so you don't need to worry too much about memory... unless it doesn't work OOTB anymore
  90. \end{itemize}
  91. Unfortunately, we:
  92. \begin{itemize}
  93. \item now got even more states to keep track of (intellectual complexity?)
  94. \item have clouded the program flow... it's now about object-interaction with their implicit states
  95. \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 missle
  96. \end{itemize}
  97. 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"? We are lucky. There is. It's called \textbf{Haskell}.
  98. \end{frame}
  99. % page 2
  100. \begin{frame}
  101. \frametitle{What is haskell?}
  102. Haskell is a \textbf{functional}, \textbf{pure}, \textbf{lazy} and \textbf{statically typed} high-level programming language.
  103. \end{frame}
  104. % page3
  105. \begin{frame}
  106. \frametitle{What does \textbf{functional} mean?}
  107. Think of haskell functions as regular \emph{mathematical} functions.
  108. \vspace{\baselineskip}
  109. \includegraphics*[scale=0.4]{function-machine.png}
  110. \begin{itemize}
  111. \item does this function write to the hard drive?
  112. \item does the output depend on anything else except the input (e.g. time, environment, ...)?
  113. \end{itemize}
  114. \end{frame}
  115. % page4
  116. \begin{frame}
  117. \frametitle{What does \textbf{functional} mean? (ctn.)}
  118. \begin{itemize}
  119. \item \emph{first-class} citizens: functions are values
  120. \item a haskell program is what happens when \emph{expressions are evaluated}
  121. \end{itemize}
  122. \end{frame}
  123. \end{document}