Pragmatic Haskell for Beginners, Lecture 1
May 14, 2016
Enough already with the project Euler problems and the monad enlightenment tutorials, how do you make real programs in Haskell? Alexandr Kurilin is going to show you! This lecture series covers starting a project, using test driven development, interacting with a database and the web, and more interesting and pragmatic examples.
In lecture one Alex walks you through starting a project, setting up a test suite, and building a program using a nice mixture of tests and types.
- What makes this series unique?
- There are a lot of resources at the very beginner side, Learn You a Haskell, Learn Haskell (git repo), NICTA Course
- And then there are the “space wizard” level articles that hardly anyone can understand
- Most people drop off at the intermediate stage. “Yeah, I’m trying to figure out functors and monads…” and then you never hear from them again
- You can be useful in Haskell without getting stuck on the theory!
- This first lecture will demonstrate the nuts and bolts of putting together a real program and doing test-driven development
- Thankfully we can skip over “Cabal hell” and use Stack. (Brief discussion of what Cabal hell means and the history leading up to Stack)
- We can start the project based on the Stack template called
stack new <project-name> franklinchen
- Check out the
<project-name>.cabalfiles. (Explanation of sections of the cabal file)
- Structure of HUnit and HSpec tests
- How to find and run tests with hspec-discover
- Starting the project: parsing a file
- What library will we use? There are a few choices
- Haskell libraries are usually poorly documented so it’s hard to tell
- The “space wizards” can unravel libraries by inspecting the function types, but the 99% of Haskellers need examples
- haskelliseasy.com curates libraries for you
- Also visit #haskell-beginners on Freenode
- We’ll use megaparsec
- Editing our code with feedback
- Showing code errors in the editor
- Discussion of “pedantic” mode in Stack
- The nature of a parser combinator
- Using an
undefinedplaceholder in TDD
- Running tests and refining our parser
- Applicatives and the alternative operator
- String vs ByteString vs Text
- What did we do? Made a parser for a simple language.
- We were able to use examples from the docs. This is what you want your Haskell experience to look like.
- Good reads