Below is the material for lectures and sessions we've had so far, crammed into one file. When only concrete parts of a book chapter are required for understading, it is marked as such in parenthesis. Which is not to say it is forbidden to read whole chapters and learn new things outside of class.
- Functional programming
- First-class functions (essence)
- Higher-order functions (essence)
- Currying (essence)
- Why functional programming? Why Haskell?
- Introduction - HaskellWiki
- Try Haskell! An interactive tutorial in your browser
- The Haskell Platform
- Function application
- Prefix and infix notation
- Disambiguating unary operations
- Logical and comparative operators
- Basic data types and literals
- Operator precedence
- Defining functions and operators
- Real World Haskell, Chapter 1 (up to “Lists”)
- Learn You a Haskell, “Starting Out” (up to “An intro to lists”)
Not related to Haskell specifically, but to programming in general.
Brush up your English. Don't gather all of your knowledge from a Russian resource like the Russian Wikipedia or “Хабрахабр”. A good chunk of that material are incorrectly-translated English articles. Fear being misinformed, read the original.
- Types
- Type systems
- Type classes
- Parametric polymorphism
- Lists and operations on lists
- Ranges
- Tuples
- Real World Haskell, Chapter 1 (only “Lists”)
- Haskell/Lists and tuples - Wikibooks (from “Tuples”)
- Real World Haskell, Chapter 2 (up to “Function application”)
- Learn You a Haskell, “Types and Typeclasses”
Try thinking about what you could do with the types you already know. Think of some functions and define their signatures. Search for functions with such signatures in Hoogle and try them in GHCi.
For example, I want to get an item from a list by its index. For an item of any
type a I need the list [a] itself and the integer index Int. The
signature [a] -> Int -> a, when searched, yields
the (!!) operator.
We've talked about some languages that implicitly change types of things when an unobvious operation happens. Examples include JavaScript and PHP. Try two answer both questions:
- How can this turn out to be a hindrance?
- On the other hand, when would this be convenient?
- Function application
- Higher-order functions
- Coditional expressions
- Guards
At this point, we've diverged from both Learn You a Haskell and Real World Haskell books that have served as our primary resources thus far. You can, however, continue reading both these books at your own pace, if you're lacking information on the topics covered.
Functions we used during the session (in alphabetical order): ($), (*),
(<=), (==), elem, filter, map, mod, not, null, odd,
otherwise, reverse, show, zip, zipWith. They all can be searched for
by name on Hoogle.
The important ones are map and filter, of course. These are higher-order
functions, and you should make sure you understand their purpose.
There's a drinking game called Bizz Buzz, the rules for which are explained on Wikipedia. It is also used as a simple programming task.
You can teach the computer to play a perfect Bizz Buzz game by making a function that takes a number and returns a list of that much consecutive Bizz Buzz rounds:
bizzbuzz :: Num a => a -> [String]Bonus points for using guards in your solution.
- Lambda expressions
- Name binding
- Pattern matching
- Folding
- Recursion
- Learn You a Haskell, Chapters 1–6
- Ten Things You Should Know About Haskell Syntax
- H-99: Ninety-Nine Haskell Problems
- Data and Codata explains two types of recursion and how it affects the computability of our programs
Here is the corrected fold implementation we did, which is actually a
right fold (or foldr):
fold' :: (a -> b -> b) -> b -> [a] -> b
fold' f init [] = init
fold' f init (x:xs) = f x (fold' f init xs)There's a bit of needless repetition here. How would you refactor this code to be shorter and more readable?
You can take a peek at the source code of the recursive functions you've seen and used. Most of them can be found in the GHC.List module (already present in the Prelude).