learnhaskell/README.md

322 lines
12 KiB
Markdown
Raw Normal View History

2014-05-19 19:43:44 +00:00
This is my recommended path for learning Haskell.
2014-05-19 19:43:26 +00:00
2014-05-19 19:43:44 +00:00
#### Something to keep in mind: *don't sweat the stuff you don't understand immediately*. Just keep moving.
# Primary course
## What are Haskell, GHC, and Cabal?
Haskell is a programming language as laid out in the reports, most recent one being in 2010. http://www.haskell.org/onlinereport/haskell2010/
GHC is the most popular compiler for Haskell and is what you'll install along with Cabal. Cabal is the project and dependency management tool used with GHC. You almost definitely want both if you're going to start writing Haskell.
Cabal is equivalent to Ruby's Bundler, Python's pip, Node's NPM, Maven, etc. GHC manages packaging itself, Cabal chooses what versions to install.
2014-05-19 19:43:44 +00:00
## Getting started
2014-05-19 20:22:18 +00:00
### Ubuntu
2014-05-19 19:43:44 +00:00
This PPA is excellent and is what I use on all my Linux dev and build machines: http://launchpad.net/~hvr/+archive/ghc
Specifically:
2014-06-04 07:56:59 +00:00
- `sudo apt-get update`
2014-05-19 21:07:22 +00:00
- `sudo apt-get install python-software-properties`
- `sudo add-apt-repository -y ppa:hvr/ghc`
- `sudo apt-get update`
- `sudo apt-get install cabal-install-1.20 ghc-7.8.2 happy-1.19.3 alex-3.1.3`
2014-05-19 19:43:44 +00:00
Then add `~/.cabal/bin:/opt/cabal/1.20/bin:/opt/ghc/7.8.2/bin:/opt/happy/1.19.3/bin:/opt/alex/3.1.3/bin` to your PATH (bash_profile, zshrc, bashrc, etc)
2014-06-23 20:19:35 +00:00
### Debian
Debian can follow the same steps as Ubuntu, but has to execute an additional command. Immediately after `sudo add-apt-repository -y ppa:hvr/ghc` is ran, run:
- `sudo sed -i s/wheezy/trusty/g /etc/apt/sources.list.d/hvr-ghc-wheezy.list`
For other Debian versions, just replace all occurences of "wheezy" with your version name in the command above.
If, for some reason, the file `/etc/apt/sources.list.d/hvr-ghc-wheezy.list` does not exist, try the same command but with `/etc/apt/sources.list` instead.
2014-05-19 20:22:18 +00:00
### Arch Linux
2014-05-19 20:18:36 +00:00
To install Haskell from the official repos on Arch Linux
Update your mirrorlist
2014-05-19 21:07:22 +00:00
- `sudo pacman -Syy`
2014-05-19 20:18:36 +00:00
Download Haskell
2014-05-19 21:07:22 +00:00
- `sudo pacman -S cabal-install ghc happy alex haddock`
2014-05-19 20:18:36 +00:00
2014-05-25 08:20:59 +00:00
### Mac OS X
Install the GHC for Mac OS X app, which includes GHC and Cabal. It provides instructions on how to add GHC and Cabal to your path after you've dropped the .app somewhere.
2014-05-31 03:34:54 +00:00
- http://ghcformacosx.github.io/
2014-05-25 08:20:59 +00:00
### Windows and other Linux users
2014-05-19 19:43:44 +00:00
Download the latest binary distributions for cabal and ghc:
#### GHC
GHC is the most popular way to work in the Haskell language. It includes a compiler, REPL (interpreter), package management, and other things besides.
2014-05-31 03:34:54 +00:00
- http://www.haskell.org/ghc/
2014-05-19 19:43:44 +00:00
#### Cabal
Cabal does project management and dependency resolution. It's how you'll install projects, typically into their own sandbox.
2014-05-31 03:34:54 +00:00
- https://www.haskell.org/cabal/download.html
2014-05-19 19:43:44 +00:00
#### Detailed manual install guide for Mac OS X
2014-05-31 03:34:54 +00:00
You don't need this if you use the .app, but if it doesn't work for you, try this with the binary distribution.
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://www.davesquared.net/2014/05/platformless-haskell.html
2014-05-19 19:43:44 +00:00
## Yorgey course - Do this first, this is the primary way I recommend being introduced to Haskell.
http://www.seas.upenn.edu/~cis194/lectures.html Brent Yorgey's course is the best I've found so far and replaces both Yann Esposito's HF&H and the NICTA course. This course is particularly valuable as it will not only equip you to write Haskell but also help you understand parser combinators.
2014-06-12 20:26:42 +00:00
## Understanding basic Haskell error messages
- http://ics.p.lodz.pl/~stolarek/_media/pl:research:stolarek_understanding_basic_haskell_error_messages.pdf
2014-05-19 19:43:44 +00:00
## Supplementary course that provides more material on intermediate topics
This is Bryan O'Sullivan's online course from the class he teaches at Stanford. If you don't know who he is, take a gander at half the libraries any Haskell application ends up needing and his name is on it. Of particular note if you've already done the Yorgey course are the modules on phantom types, information flow control, language extensions, concurrency, pipes, and lenses.
2014-05-31 03:34:54 +00:00
- http://www.scs.stanford.edu/14sp-cs240h/
2014-05-19 19:43:44 +00:00
## Development Environment
### Emacs
2014-05-31 03:34:54 +00:00
- http://tim.dysinger.net/posts/2014-02-18-haskell-with-emacs.html
2014-05-19 19:43:44 +00:00
2014-06-10 18:43:20 +00:00
- https://github.com/chrisdone/chrisdone-emacs
- https://github.com/bitemyapp/dotfiles/
2014-05-19 19:43:44 +00:00
### Vim
2014-05-31 03:34:54 +00:00
- http://www.haskell.org/haskellwiki/Vim
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://www.stephendiehl.com/posts/vim_haskell.html
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- https://github.com/kazu-yamamoto/ghc-mod
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- https://github.com/eagletmt/ghcmod-vim
2014-05-19 19:43:44 +00:00
### Sublime Text
2014-05-31 03:34:54 +00:00
- https://github.com/SublimeHaskell/SublimeHaskell
2014-05-19 19:43:44 +00:00
## FAQ and working with Cabal
### Fantastic FAQ
2014-05-31 03:34:54 +00:00
In addition to being an amazing guide for all kinds of things such as GADTs, this also covers some useful basics for Cabal
- http://dev.stephendiehl.com/hask/
2014-05-19 19:43:44 +00:00
### Cabal guidelines
2014-06-13 02:27:37 +00:00
- http://katychuang.com/cabal-guide/ Cabal - the simple guide
2014-05-19 19:43:44 +00:00
Cabal Hell was a problem for Haskell users before the introduction of sandboxes. Installing outside of a sandbox will install into your user package-db. This is *not* a good idea except for foundational packages like Cabal, alex, and happy. Nothing else should be installed in the user or global package-dbs unless you know what you're doing.
To experiment with a package or start a project, begin by doing `cabal sandbox init` in a new directory.
Put briefly:
- Always use sandboxes for installing new packages, building new or existing projects, or starting experiments
- Use `cabal repl` to start a project-scoped ghci instance
2014-06-06 21:34:00 +00:00
The sandbox-based approach I suggest should avoid package-dependency problems, but it's incompatible with the way the Haskell Platform provides pre-built packages. If you're still learning Haskell and don't understand how ghc-pkg and Cabal work, *avoid Platform* and instead use the install instructions earlier in the guide.
2014-05-19 19:43:44 +00:00
## Exercises for practice
You should do Yorgey's course before attempting this: https://github.com/NICTA/course/
## Secondary material, references
[Learn You a Haskell for Great Good (LYAH)](http://learnyouahaskell.com) and [Real World Haskell](http://book.realworldhaskell.org) (Thanks bos!) are available online.
2014-05-19 19:43:44 +00:00
I recommend RWH as a reference (thick book). The chapters for parsing and monads are great for getting a sense for where monads are useful. Other people have said that they've liked it a lot. Perhaps a good follow-up for practical idioms after you've got the essentials of Haskell down?
## For learning some common typeclasses
Useful for understanding typeclasses in general but also some Hask-specific category theory:
2014-05-31 03:34:54 +00:00
- http://www.haskell.org/haskellwiki/Typeclassopedia
2014-05-19 19:43:44 +00:00
## Search code by type signature
The Hoogle search engine can search by type:
http://www.haskell.org/hoogle/?hoogle=%28a+-%3E+b%29+-%3E+%5ba%5d+-%3E+%5bb%5d
Alternately:
https://www.fpcomplete.com/hoogle
Also Hayoo (which has all of hackage enabled for search by default): http://holumbus.fh-wedel.de/hayoo/hayoo.html
### Setting up your own local instance of Hoogle
https://gist.github.com/bitemyapp/3e6a015760775e0679bf
2014-05-19 19:43:44 +00:00
## Fun Stuff
After you're comfortable with Haskell, strongly consider learning Lenses and Prisms, even if just as a "user". You don't need to understand the underlying category for it to be useful.
Seen here: http://hackage.haskell.org/package/lens
## Frontend/JavaScript
2014-05-19 19:47:45 +00:00
If you need JavaScript, you probably want Purescript for generating JS. Purescript is *not* strictly Haskell but it is very similar and quite pleasant.
2014-05-19 19:43:44 +00:00
- http://www.purescript.org/
- http://try.purescript.org/
## Laziness, strictness, guarded recursion
2014-06-21 17:44:08 +00:00
- http://chimera.labs.oreilly.com/books/1230000000929/ch02.html Marlow's book about parallelism and concurrency has one of the best introductions to laziness and normal form I've found. Use other material too if it doesn't stick immediately.
2014-06-09 21:04:35 +00:00
2014-06-21 17:44:08 +00:00
- http://augustss.blogspot.hu/2011/05/more-points-for-lazy-evaluation-in.html
2014-06-21 17:44:08 +00:00
- http://alpmestan.com/2013/10/02/oh-my-laziness/
2014-06-21 17:44:08 +00:00
- http://stackoverflow.com/questions/13042353/does-haskell-have-tail-recursive-optimization
- http://www.slideshare.net/tibbe/reasoning-about-laziness
2014-06-09 21:04:35 +00:00
```haskell
let a = 1 : a -- guarded recursion, (:) is lazy and can be pattern matched.
2014-06-05 22:42:40 +00:00
let (v : _) = a
> v
1
> head a -- head a == v
1
let a = 1 * a -- not guarded, (*) is strict
> a
*** Exception: <<loop>>
```
2014-06-21 17:44:08 +00:00
- http://www.vex.net/~trebla/haskell/lazy.xhtml
2014-06-09 21:04:35 +00:00
2014-05-19 19:43:44 +00:00
## Parallelism/Concurrency
2014-05-31 03:34:54 +00:00
- http://chimera.labs.oreilly.com/books/1230000000929 This book by Simon Marlow is probably the best I've ever read on the topics of Parallelism and Concurrency:
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://kukuruku.co/hub/haskell/haskell-testing-a-multithread-application A thorough walk-through on testing & incremental development of a multi-threaded application in Haskell
2014-05-31 03:34:54 +00:00
- http://www.haskell.org/haskellwiki/Functional_Reactive_Programming
2014-05-19 19:43:44 +00:00
## Recursion Schemes
Some of the crazy *-morphism words you've heard are actually about recursion. NB - before tackling this material you should know how to implement foldr for lists and at least one other data structure, such as a tree. (folds are catamorphisms) Knowing how to implement an unfold (anamorphism) for the same will round things out a bit.
This material dovetails with traversable and foldable.
2014-05-31 03:34:54 +00:00
- http://patrickthomson.ghost.io/an-introduction-to-recursion-schemes/
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://fho.f12n.de/posts/2014-05-07-dont-fear-the-cat.html - good demonstration of how hylomorphism is the composition of cata and ana.
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://comonad.com/reader/2009/recursion-schemes/ - this field guide is excellent.
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://eprints.eemcs.utwente.nl/7281/01/db-utwente-40501F46.pdf
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- https://www.fpcomplete.com/user/edwardk/recursion-schemes/catamorphisms
2014-05-19 19:43:44 +00:00
## Lenses and Prisms
People vastly overestimate the difficulty of using Lens. Anybody comfortable with Functor/Foldable/Traversable (or even just the first one) can leverage lenses and prisms to make their life happier.
2014-05-19 19:47:45 +00:00
If you've ever done something like: `(fmap . fmap)` you were "lensing" in your head.
2014-05-19 19:43:44 +00:00
I recommend these two tutorials/introductions:
2014-05-31 03:34:54 +00:00
- https://www.fpcomplete.com/school/to-infinity-and-beyond/pick-of-the-week/a-little-lens-starter-tutorial
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- https://github.com/ekmett/lens#lens-lenses-folds-and-traversals
2014-05-19 19:43:44 +00:00
## Type and Category Theory (*not* needed to actually write Haskell, just for those interested!)
If you want to follow up on the type and category theory:
2014-05-31 03:34:54 +00:00
- http://www.cs.cmu.edu/~rwh/plbook/book.pdf Harper's Practical Foundations for Programming Languages is the best PL focused intro to type theory I've read.
2014-05-19 19:43:44 +00:00
- http://www.quora.com/Category-Theory/What-is-the-best-textbook-for-Category-theory?share=1 Kmett's recommendations
2014-05-31 03:34:54 +00:00
- http://en.wikibooks.org/wiki/Haskell/Category_theory nice diagrams
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://www.haskell.org/haskellwiki/Category_theory good links to other resources
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://science.raphael.poss.name/categories-from-scratch.html includes practical examples
2014-05-25 12:09:02 +00:00
2014-05-31 03:34:54 +00:00
- https://www.google.com/search?q=Awodey+Category+Theory the standard text along with MacLane
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://www.cs.kent.ac.uk/people/staff/sjt/TTFP/
2014-05-19 19:43:44 +00:00
2014-06-03 11:24:43 +00:00
- http://www.cis.upenn.edu/~bcpierce/courses/670Fall04/GreatWorksInPL.shtml Pierce's Great Works in PL list
### Stephen's Nifty "How to get to monad" posts
Didn't know where else to put these:
- http://www.stephendiehl.com/posts/adjunctions.html
- http://www.stephendiehl.com/posts/monads.html
2014-06-20 15:29:04 +00:00
## Parametricity, ad-hoc vs. parametric polymorphism, free theorems
- http://dl.dropboxusercontent.com/u/7810909/media/doc/parametricity.pdf
- https://github.com/tonymorris/parametricity/
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://swizec.com/blog/week-20-making-ad-hoc-polymorphism-less-ad-hoc/swizec/6564
2014-05-19 19:43:44 +00:00
2014-05-31 03:34:54 +00:00
- http://ttic.uchicago.edu/~dreyer/course/papers/wadler.pdf
2014-05-19 19:43:44 +00:00
2014-06-04 20:34:47 +00:00
## Initial and Final, DSLs, Finally Tagless
- http://martijn.van.steenbergen.nl/journal/2009/10/18/transforming-polymorphic-values/
- http://martijn.van.steenbergen.nl/journal/2009/11/12/gadts-in-haskell-98/
- https://www.fpcomplete.com/user/mutjida/typed-tagless-final-linear-lambda-calculus
- http://okmij.org/ftp/tagless-final/course/course.html
- http://okmij.org/ftp/tagless-final/course/lecture.pdf
- http://existentialtype.wordpress.com/2011/03/21/the-dog-that-didnt-bark/ less specifically relevant but interesting
2014-06-03 11:24:43 +00:00
## Comonads
- https://speakerdeck.com/dmoverton/comonads-in-haskell
2014-06-03 11:27:42 +00:00
- http://stackoverflow.com/questions/16551734/can-a-monad-be-a-comonad
2014-06-03 11:24:43 +00:00
## Yoneda / CoYoneda
- http://stackoverflow.com/questions/24000465/step-by-step-deep-explain-the-power-of-coyoneda-preferably-in-scala-throu
## Dependent typing
- http://bitemyapp.com/posts/2014-04-05-grokking-sums-and-constructors.html squint hard.
- http://okmij.org/ftp/Computation/lightweight-dependent-typing.html
- http://www.idris-lang.org/
2014-05-19 19:43:44 +00:00
## Extended Reading list (some is already included here)
2014-05-31 03:34:54 +00:00
- http://www.stephendiehl.com/posts/essential_haskell.html