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.
 
 
 

140 lines
4.6 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 accesses 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 what happens if the program flow reaches this codepath with variable X in that particular state, while variable Z is NULL, and...
  80. \item did you just nuke a small former Soviet state?
  81. \end{itemize}
  82. \vspace{\baselineskip}
  83. Conclusion: you really need to understand the complete environment of that line/function.
  84. \end{frame}
  85. \begin{frame}
  86. \frametitle{Why haskell? (ctn.)}
  87. But java helps! Does it?
  88. Sort of, because:
  89. \begin{itemize}
  90. \item it improves APIs compared to C, since you can hide or encapsulate information in the state of an object
  91. \item it has a garbage collector, so you don't need to worry too much about memory
  92. \end{itemize}
  93. Unfortunately, we:
  94. \begin{itemize}
  95. \item now got even more states to keep track of (intellectual complexity?)
  96. \item have clouded the program flow... it's now about object-interaction with their explicit and implicit states
  97. \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
  98. \end{itemize}
  99. 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}.
  100. \end{frame}
  101. % page 2
  102. \begin{frame}
  103. \frametitle{What is haskell?}
  104. Haskell is a \textbf{functional}, \textbf{pure}, \textbf{lazy} and \textbf{statically typed} high-level programming language.
  105. \end{frame}
  106. % page3
  107. \begin{frame}
  108. \frametitle{What does \textbf{functional} mean?}
  109. Think of haskell functions as regular \emph{mathematical} functions.
  110. \vspace{\baselineskip}
  111. \includegraphics*[scale=0.4]{function-machine.png}
  112. \begin{itemize}
  113. \item does this function write to the hard drive?
  114. \item does the output depend on anything else except the input (e.g. time, environment, ...)?
  115. \end{itemize}
  116. \end{frame}
  117. % page4
  118. \begin{frame}
  119. \frametitle{What does \textbf{functional} mean? (ctn.)}
  120. \begin{itemize}
  121. \item \emph{first-class} citizens: functions are values
  122. \item a haskell program is what happens when \emph{expressions are evaluated}
  123. \end{itemize}
  124. \end{frame}
  125. \end{document}