\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{xonnex} \pdfinfo{ /Title (haskell.pdf) /Creator (Cheatography) /Author (xonnex) /Subject (Haskell Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Haskell Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{xonnex} via \textcolor{DarkBackground}{\uline{cheatography.com/196187/cs/41216/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}xonnex \\ \uline{cheatography.com/xonnex} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 7th November, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{4} \begin{tabularx}{3.833cm}{p{0.3433 cm} x{3.0897 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Class Constraints}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Eq – equality types} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} & Contains types whose values can be compared for equality and inequality \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} & methods: (==), (/=) \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Ord – ordered types} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} & Contains types whose values are totally ordered \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} & methods: (\textless{}), (\textless{}=), (\textgreater{}), (\textgreater{}=), min, max \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Show – showable types} \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} & Contains types whose values can be converted into strings of characters \tn % Row Count 12 (+ 2) % Row 8 \SetRowColor{LightBackground} & method show :: a -\textgreater{} String \tn % Row Count 13 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Num – numeric types} \tn % Row Count 14 (+ 1) % Row 10 \SetRowColor{LightBackground} & Contains types whose values are numeric \tn % Row Count 16 (+ 2) % Row 11 \SetRowColor{white} & methods: (+), (-), (*), negate, abs, signum \tn % Row Count 18 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Integral – integral types} \tn % Row Count 19 (+ 1) % Row 13 \SetRowColor{white} & Contains types that are numeric but of integral value \tn % Row Count 21 (+ 2) % Row 14 \SetRowColor{LightBackground} & methods: div, mod \tn % Row Count 22 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Fractional – fractional types} \tn % Row Count 23 (+ 1) % Row 16 \SetRowColor{LightBackground} & Contains types that are numeric but of fractional value \tn % Row Count 25 (+ 2) % Row 17 \SetRowColor{white} & methods: (/), recip \tn % Row Count 26 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.58361 cm} x{2.84939 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Predefined Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{cos} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{sin} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} fst & first argument \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} snd & second argument \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} show & display (will display "\textbackslash{}246" instead of "{\"o}") \tn % Row Count 6 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{putStrLn} & IO display (will display "{\"o}") \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{import Data.Char} \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{isDigit 'a'} \tn % Row Count 10 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{isUpperCase 'a'} \tn % Row Count 11 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Predefined Constants}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{pi} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{3.0897 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Pattern Matching}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{fstInt :: (Int, Int) -\textgreater{} Int} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{fstInt (x, y) = x} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} fstInt (1, 3) & 1 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{} \tn % Row Count 3 (+ 0) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{sayNumber :: Int -\textgreater{} String -\textgreater{} String} \tn % Row Count 4 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{sayNumber 1 s = "One " ++ s} \tn % Row Count 5 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{sayNumber n s = "Many " ++ s ++ "s"} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{constants like 0, {[}{]} or an enum \newline names like n \newline wildcard "\_" (matches always but binds no name to the matched value) \newline structures like lists (x:xs) or tuples (a,b)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.3732 cm} x{2.0598 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Commands}} \tn % Row 0 \SetRowColor{LightBackground} cabal run & Runs cabal project \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} ghci & Open interactive shell \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} ghci fileName.hs & Open shell and load file \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{data Color = Red | Yellow | Green deriving (Show)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{data ToDo = Stop | Wait | Go deriving (Show)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{atTrafficLight :: Color -\textgreater{} ToDo} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{atTrafficLight Red = Stop} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{atTrafficLight Yellow = Wait} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{atTrafficLight Green = Go} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{"-\textgreater{}" whenever the arrow is shown, we have ourselves a function} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.75083 cm} x{1.68217 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{ghci}} \tn % Row 0 \SetRowColor{LightBackground} :r & reload file \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} :q & quit \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} :t var & show type of var \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} :i + & show type of operator \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} :\{ & start multiline \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} :\} & end multiline \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} (var1, var2, ...) :: (Type1, Type2, ...) & Validates type \tn % Row Count 9 (+ 2) % Row 7 \SetRowColor{white} \{-\# OPTIONS\_GHC -Wall \#-\} & Shows info in case something is missing \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Bool}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{True} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{False} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{a \&\& b} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{a || b} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{not a} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.13289 cm} x{2.30011 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Lists}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{[}1,2,3,4{]}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{[}(1,2),(3,4){]}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{ones = 1 : ones} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} head {[}1,2,3{]} & 1 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} tail {[}1,2,3{]} & {[}2,3{]} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} init {[}1,2,3{]} & {[}1,2{]} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} last {[}1,2,3{]} & 3 \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} take 2 {[}1,2,3{]} & {[}1,2{]} \tn % Row Count 9 (+ 2) % Row 8 \SetRowColor{LightBackground} uncons {[}1,2,3{]} & Just (1, {[}2,3{]}) \tn % Row Count 11 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{map :: (a -\textgreater{} b) -\textgreater{} {[}a{]} -\textgreater{} {[}b{]}} \tn % Row Count 12 (+ 1) % Row 10 \SetRowColor{LightBackground} map (+1) {[}1, 2, 3{]} & {[}2,3,4{]} \tn % Row Count 14 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{filter :: (a -\textgreater{} Bool) -\textgreater{} {[}a{]} -\textgreater{} {[}a{]}} \tn % Row Count 15 (+ 1) % Row 12 \SetRowColor{LightBackground} filter odd {[}1, 2, 3{]} & {[}1,3{]} \tn % Row Count 17 (+ 2) % Row 13 \SetRowColor{white} null {[}{]} & \textasciitilde{}\textgreater{} True -{}- Checks whether list is empty (performant) \tn % Row Count 19 (+ 2) % Row 14 \SetRowColor{LightBackground} length {[}{]} & \textasciitilde{}\textgreater{} 0 -{}- Checks length (need to go through the whole list) \tn % Row Count 22 (+ 3) % Row 15 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{} \tn % Row Count 22 (+ 0) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{[}a,b,c{]} = a : (b : (c : {[}{]}))} \tn % Row Count 23 (+ 1) % Row 17 \SetRowColor{white} {[}{]} & nil \tn % Row Count 24 (+ 1) % Row 18 \SetRowColor{LightBackground} (:) & cons operator \tn % Row Count 25 (+ 1) % Row 19 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{} \tn % Row Count 25 (+ 0) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{stdMatch :: Show a =\textgreater{} {[}a{]} -\textgreater{} String} \tn % Row Count 26 (+ 1) % Row 21 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{stdMatch {[}{]} = "Matched empty list"} \tn % Row Count 27 (+ 1) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{stdMatch (x:xs) = "Matched list with head " ++ show x} \tn % Row Count 29 (+ 2) % Row 23 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{} \tn % Row Count 29 (+ 0) % Row 24 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{ml :: Show a =\textgreater{} {[}a{]} -\textgreater{} String} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{x{1.13289 cm} x{2.30011 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Lists (cont)}} \tn % Row 25 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{ml {[}x{]} = "Matched list with one element" ++ show x} \tn % Row Count 2 (+ 2) % Row 26 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{ml {[}x,y{]} = "Matched list with two elements"} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{sequence of elements of the same type \newline infinite amount of elements \newline immutable \newline "++" concat two lists} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{2.43743 cm} x{0.99557 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{String}} \tn % Row 0 \SetRowColor{LightBackground} reverse "abc" & "cba" \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {[}'a','b','c'{]} == "abc" & True \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} "Foo" ++ " " ++ "Bar" & "Foo Bar" \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{String = {[}Char{]}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Chars}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{'a', ,} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{' '} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{'\textbackslash{}n'} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} x{3.0897 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Where Bindings}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{amountToText :: Int -\textgreater{} String} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{amountToText amount} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} & | amount \textgreater{}= high = "Many" \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} & | amount \textgreater{}= mid = "Medium" \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} & | otherwise = "Low" \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} & where \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} & high = 10 \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} & mid = 5 \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} x{3.0897 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Conditional Expressions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{if a == b} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} & then "Eq" \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} & else "Not Eq" \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} x{3.0897 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Where Bindings}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{amountToText :: Int -\textgreater{} String} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{amountToText amount} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} & | amount \textgreater{}= high = "Many" \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} & | amount \textgreater{}= mid = "Medium" \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} & | otherwise = "Low" \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} & where \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} & high = 10 \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} & mid = 5 \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} x{3.0897 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Guards}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{abs :: (Num a, Ord a) =\textgreater{} a -\textgreater{} a} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{abs n} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} & | n \textless{} 0 = -n \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} & | otherwise = n \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Function Composition}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{g . f = \textbackslash{}x -\textgreater{} g (f x)} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.0299 cm} x{2.4031 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Lambda Expressions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{\textbackslash{}x -\textgreater{} x + 1} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \textbackslash{}p q -\textgreater{} e & same as \textbackslash{}p -\textgreater{} \textbackslash{}q -\textgreater{} e \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} x{3.0897 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Let Bindings}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{cylinder :: Float -\textgreater{} Float -\textgreater{} Float} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{cylinder r h =} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} & let sideArea = 2 {\emph{ pi }} r * h \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} & topArea = pi * r \textasciicircum{} 2 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} & in 2 * topArea + sideArea \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Double}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Floating Point Number 64 bit} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} x{3.0897 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Case Expressions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{case expression of} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} & pattern -\textgreater{} result \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} & pattern -\textgreater{} result \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{} \tn % Row Count 3 (+ 0) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{describeList :: {[}a{]} -\textgreater{} String} \tn % Row Count 4 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{describeList xs = "The list is " ++ case xs of} \tn % Row Count 5 (+ 1) % Row 6 \SetRowColor{LightBackground} & {[}{]} -\textgreater{} "empty." \tn % Row Count 6 (+ 1) % Row 7 \SetRowColor{white} & {[}x{]} -\textgreater{} "a singleton list." \tn % Row Count 7 (+ 1) % Row 8 \SetRowColor{LightBackground} & xs -\textgreater{} "a longer list." \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{0.96124 cm} x{2.47176 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Integer}} \tn % Row 0 \SetRowColor{LightBackground} maxBound :: Int & max int \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} 45 & literals will always default to Integer \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{long in Java 2\textasciicircum{}64} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.61351 cm} x{1.81949 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Record Types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{data Person = MkPerson \{ name :: String, age :: Int \} deriving (Show)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{me = MkPerson "XonneX" 99} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} name me & "XonneX" \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} age me & 99 \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.99114 cm} x{1.44186 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Type Synonyms}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{type Coord = (Int, Int)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{xCoord :: Coord -\textgreater{} Int} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{xCoord (x, y) = x} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{time :: (Int, Int)} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{time = (23, 59)} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} xCoord time & compiles \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{The keyword type can be used to introduce a new name (a synonym) for an existing type. \newline This does not create a new type, only a new name!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Tuples}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{(False, 8, "Hallo") :: (Bool, Int, String)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{((True, 8), (12, "Hallo")) :: ((True, 8), (12, "Hallo"))} \tn % Row Count 3 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.6866 cm} x{2.7464 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Enumerations}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{data Color = Red | Yellow | Green} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} show Green & Would fail as no toString method is not implemented \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{data Color = Red | Yellow | Green deriving (Show)} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} show Green & Displays "Green" as toString method is implemented \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{3.0897 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{(|+|) :: Int -\textgreater{} Int -\textgreater{} Int} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{a |+| b = abs a + abs b} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} 1 |+| (-2) & 3 \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}