Post on 20-Dec-2018

220 views

Category:

## Documents

Embed Size (px)

TRANSCRIPT

Notes for Professionals

GoalKicker.comFree Programming Books

DisclaimerThis is an unocial free book created for educational purposes and is

the property of their respective owners

200+ pagesof professional hints and tricks

https://goalkicker.comhttps://goalkicker.com

ContentsAbout 1 ................................................................................................................................................................................... Chapter 1: Getting started with Haskell Language 2 .....................................................................................

Section 1.1: Getting started 2 ............................................................................................................................................ Section 1.2: Hello, World! 4 ............................................................................................................................................... Section 1.3: Factorial 6 ...................................................................................................................................................... Section 1.4: Fibonacci, Using Lazy Evaluation 6 ............................................................................................................ Section 1.5: Primes 7 ......................................................................................................................................................... Section 1.6: Declaring Values 8 ........................................................................................................................................

Chapter 2: Overloaded Literals 10 ........................................................................................................................... Section 2.1: Strings 10 ....................................................................................................................................................... Section 2.2: Floating Numeral 10 .................................................................................................................................... Section 2.3: Integer Numeral 11 ...................................................................................................................................... Section 2.4: List Literals 11 ..............................................................................................................................................

Chapter 3: Foldable 13 ................................................................................................................................................... Section 3.1: Definition of Foldable 13 .............................................................................................................................. Section 3.2: An instance of Foldable for a binary tree 13 ............................................................................................ Section 3.3: Counting the elements of a Foldable structure 14 ................................................................................... Section 3.4: Folding a structure in reverse 14 ............................................................................................................... Section 3.5: Flattening a Foldable structure into a list 15 ............................................................................................ Section 3.6: Performing a side-eect for each element of a Foldable structure 15 ................................................. Section 3.7: Flattening a Foldable structure into a Monoid 16 .................................................................................... Section 3.8: Checking if a Foldable structure is empty 16 ...........................................................................................

Chapter 4: Traversable 18 ........................................................................................................................................... Section 4.1: Definition of Traversable 18 ........................................................................................................................ Section 4.2: Traversing a structure in reverse 18 ......................................................................................................... Section 4.3: An instance of Traversable for a binary tree 19 ...................................................................................... Section 4.4: Traversable structures as shapes with contents 20 ................................................................................ Section 4.5: Instantiating Functor and Foldable for a Traversable structure 20 ....................................................... Section 4.6: Transforming a Traversable structure with the aid of an accumulating parameter 21 ...................... Section 4.7: Transposing a list of lists 22 .......................................................................................................................

Chapter 5: Lens 24 ............................................................................................................................................................ Section 5.1: Lenses for records 24 ................................................................................................................................... Section 5.2: Manipulating tuples with Lens 24 ............................................................................................................... Section 5.3: Lens and Prism 25 ........................................................................................................................................ Section 5.4: Stateful Lenses 25 ........................................................................................................................................ Section 5.5: Lenses compose 26 ..................................................................................................................................... Section 5.6: Writing a lens without Template Haskell 26 ............................................................................................. Section 5.7: Fields with makeFields 27 ........................................................................................................................... Section 5.8: Classy Lenses 29 .......................................................................................................................................... Section 5.9: Traversals 29 ................................................................................................................................................

Chapter 6: QuickCheck 30 ............................................................................................................................................. Section 6.1: Declaring a property 30 ............................................................................................................................... Section 6.2: Randomly generating data for custom types 30 ..................................................................................... Section 6.3: Using implication (==>) to check properties with preconditions 30 ........................................................ Section 6.4: Checking a single property 30 ................................................................................................................... Section 6.5: Checking all the properties in a file 31 ...................................................................................................... Section 6.6: Limiting the size of test data 31 .................................................................................................................

Chapter 7: Common GHC Language Extensions 33 ......................................................................................... Section 7.1: RankNTypes 33 ............................................................................................................................................. Section 7.2: OverloadedStrings 33 .................................................................................................................................. Section 7.3: BinaryLiterals 34 .......................................................................................................................................... Section 7.4: ExistentialQuantification 34 ........................................................................................................................ Section 7.5: LambdaCase 35 ........................................................................................................................................... Section 7.6: FunctionalDependencies 36 ........................................................................................................................ Section 7.7: FlexibleInstances 36 ..................................................................................................................................... Section 7.8: GADTs 37 ...................................................................................................................................................... Section 7.9: TupleSections 37 .......................................................................................................................................... Section 7.10: OverloadedLists 38 ..................................................................................................................................... Section 7.11: MultiParamTypeClasses 38 ............................................................................................................