Friendly Haskell (WIP)
A friendly document for beginner to learn Haskell.
This documentation assumes that you have no FP background but know how to use Terminal and have Visual Studio Code or any other editors you prefer installed on your Linux/MacOS/ machine.
Haskell taught me way more about functional programming than all the other languages put together. It is optimized for developer efficiency. You can get a lot done, have a high degree of confidence that it runs reasonably without having to do too much thinking or ass-covering. We move fast & need things to be reliable. Rather than hand optimizing Doom 2 for ___, Haskell is the opposite. The computers serve us. Code is for humans to read, and only incidentally for computers to read. Code is how humans express themselves to each other and computers, and it’s up to computers to run it in a reasonably good way.
Super Power for Preventing Errors and Reducing Cognitive Load
Haskell is really an underrated super power for building backends and web apps. The ecosystem has improved quite a lot over the recent years. With the Haskell Language Server and the Haskell Plugin for VS Code there's now really nice editor support. The language itself is also improving at a good pace, e.g. the latest release of GHC (The haskell compiler) added support for dot-notation, so you can now write
someValue.someField as you might know from other languages.
I was in a Haskell team at big co, and have trained groups at various companies professionally. From that experience, for a normal developer with working experience in Java, Python, or C++:
- It takes 2-3 weeks of full-time onboarding (half with a coach, half self-study) to work on a typical industrial Haskell project.
- It takes around 3 months of full-time participation in such a project to know a wide array of libraries and feel ready to tackle almost anything.
The companies involved were happy to make this time investment for increased productivity over the time they expected their employees to stay with them.
On an individual level, it makes sense that if you're just getting into programming, and you have the choice betweeninvesting 2 weeks into Python to be productive, or 3 months for Haskell, you pick Python. It's rational. But after you'vebeen in it for a few years, and you realise you want to do it for another 40 years, investing 3 months for life-longincreased productivity (even if it's just a few percentage points; most feel the effect is larger) suddenly becomes a greatdeal.
I only recommend to install GHC, cabal-install and haskell-language-server via GHCup
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
- Don't "install" things. Declare them as dependencies of your project, and then cabal will bring them into scope when compiling, using the repl, calling cabal exec, etc..
- I would just put everything in a do block in main and go wild.
- IHP: Batteries included and glue is taken care of for you. Might not be the best if you want to learn the deeper Haskell topics though. It doesn’t give you much wiggle room to decide but this is good if you want to avoid analysis paralysis, and if what it offers fits your use case.
- Yesod: Batteries included but modular so you can opt out certain things if you want to do it a certain way. It’s opinionated but not too much. Mercury.com uses it along with React + TS iirc.
- Servant: Less opinionated and it defers to you to make a lot of decisions. Complex and can trigger your flight or fight response with its wall of text for error messages, but you can generate client functions, documentation, Swagger just from specifying your endpoints. Not that opinionated so you have to figure things out yourself. Only supports a limited set of languages for its client codegen though; right now it’s Elm and JS. Mercury seems to be working on a project to support briding Kotlin and Swift types but it still seems like a WIP.
- Spock/Scotty: If you want something more barebones but not as complex as Servant due to not needing its codegen.
- wai: Pretty much as barebones as it gets. Majority of the web frameworks use wai under the hood.