State of the Haskell ecosystem
In this post I will describe the current state of the Haskell ecosystem to the best of my knowledge and its suitability for various programming domains and tasks. The purpose of this post is to discuss both the good and the bad by advertising where Haskell shines while highlighting where I believe there is room for improvement.
This post is grouped into two sections: the first section covers Haskell's suitability for particular programming application domains (i.e. servers, games, or data science) and the second section covers Haskell's suitability for common general-purpose programming needs (such as testing, IDEs, or concurrency).
The topics are roughly sorted from greatest strengths to greatest weaknesses. Each programming area will also be summarized by a single rating of either:
- Best in class: the best experience in any language
- Mature: suitable for most programmers
- Immature: only acceptable for early-adopters
- Bad: pretty unusable
The more positive the rating the more I will support the rating with success stories in the wild. The more negative the rating the more I will offer constructive advice for how to improve things.
Disclaimer #1: I obviously don't know everything about the Haskell ecosystem, so whenever I am unsure I will make a ballpark guess and clearly state my uncertainty in order to solicit opinions from others who have more experience. I keep tabs on the Haskell ecosystem pretty well, but even this post is stretching my knowledge. If you believe any of my ratings are incorrect, I am more than happy to accept corrections (both upwards and downwards)
Disclaimer #2: There are some "Educational resource" sections below which are remarkably devoid of books, since I am not as familiar with textbook-related resources. If you have suggestions for textbooks to add, please let me know.
Disclaimer #3: I am very obviously a Haskell fanboy if you haven't guessed from the name of my blog and I am also an author of several libraries mentioned below, so I'm highly biased. I've made a sincere effort to honestly appraise the language, but please challenge my ratings if you believe that my bias is blinding me! I've also clearly marked Haskell sales pitches as "Propaganda" in my external link sections. :)
Disclaimer #4: I've contributed the majority of these recommendations and I also play an editorial role. This means that although some contributions have been crowd-sourced I reserve the right to decline a pull request or edit/delete content if I feel that a resource is abandoned or if I feel there are better alternatives already listed. I try to be as fair as possible and if you disagree with any decision of mine or you feel that my recommendation does not reflect the consensus of the Haskell community you can challenge my decision by opening an issue and I will either defend my decision or change my mind.
Table of Contents
- Application Domains
🏆Compilers 🥈Server-side web programming 🥈Scripting / Command-line applications 🌱Data science 🌱Numerical programming 🌱Front-end web programming 🌱Distributed programming 🌱Standalone GUI applications 🌱Machine learning 🌱Game programming 🌱ARM processor support 🌱Computer Vision 🌱Mobile apps 🌱/ ⛔Systems / embedded programming
- Common Programming Needs
🏆Maintenance 🏆Single-machine Concurrency 🏆Types / Type-driven development 🏆Parsing / Pretty-printing 🥈Domain-specific languages (DSLs) 🥈Testing 🥈Data structures and algorithms 🥈Benchmarking 🥈Unicode 🥈Stream programming 🥈Serialization / Deserialization 🥈Support for file formats 🥈Package management 🥈Logging 🥈Code formatting 🌱Education 🌱Databases and data stores 🌱Debugging 🌱Cross-platform support 🌱Hot code loading 🌱IDE support
Rating: Best in class
Haskell is an amazing language for writing your own compiler. If you are writing a compiler in another language you should genuinely consider switching.
Haskell originated in academia, and most languages of academic origin (such as the ML family of languages) excel at compiler-related tasks for obvious reasons. As a result the language has a rich ecosystem of libraries dedicated to compiler-related tasks, such as parsing, pretty-printing, unification, bound variables, syntax tree manipulations, and optimization.
Anybody who has ever written a compiler knows how difficult they are to implement because by necessity they manipulate very weakly typed data structures (trees and maps of strings and integers). Consequently, there is a huge margin for error in everything a compiler does, from type-checking to optimization, to code generation. Haskell knocks this out of the park, though, with a really powerful type system with many extensions that can eliminate large classes of errors at compile time.
I also believe that there are many excellent educational resources for compiler writers, both papers and books. I'm not the best person to summarize all the educational resources available, but the ones that I have read have been very high quality.
Finally, there are a large number of parsers and pretty-printers for other languages which you can use to write compilers to or from these languages.
happy- parsing libraries
unbound- manipulating bound variables
uuagc- attribute grammars
unification-fd- fast structural unification
llvm-general- LLVM 3.5 API
llvm-hs- LLVM 5 API (actively maintained fork of llvm-general)
cil} - parsers and pretty-printers for other languages
Some compilers written in Haskell:
Pugs(the first Perl 6 implementation)
frege(very similar to Haskell, also self-hosting)
hython(a Python3 interpreter written in Haskell)
Lasca(a small Scala-like language with global type inference and optional dynamic mode on LLVM backend)
verve- Functional language with object-oriented support
sixten- Haskell/Idris-style language with a focus on precise and efficient memory layout
carp- An efficient, statically typed Lisp with ownership tracking.
unison- A purely functional distributed programming language with algebraic effects.
oden(no longer in active development)
- Write you a Haskell
- A Tutorial Implementation of a Dependently Typed Lambda Calculus
- Binders Unbound
Server-side web programming
Haskell's second biggest strength is the back-end, both for web applications and services. The main features that the language brings to the table are:
- Server stability
- Ease of concurrent programming
- Excellent support for web standards
The strong type system and polished runtime greatly improve server stability and simplify maintenance. This is the greatest differentiator of Haskell from other backend languages, because it significantly reduces the total-cost-of-ownership. You should expect that you can maintain Haskell-based services with significantly fewer programmers than other languages, even when compared to other statically typed languages.
However, the greatest weakness of server stability is space leaks. The most
common solution that I know of is to use
ekg (a process monitor) to examine
a server's memory stability before deploying to production. The second most
common solution is to learn to detect and prevent space leaks with experience,
which is not as hard as people think.
Haskell's performance is excellent and currently comparable to Java. Both languages give roughly the same performance in beginner or expert hands, although for different reasons.
Where Haskell shines in usability is the runtime support for the following three features:
- software transactional memory (which differentiates Haskell from Go)
- lightweight threads that use non-blocking I/O (which differentiates Haskell from the JVM)
- garbage collection (which differentiates Haskell from Rust)
If you have never tried out Haskell's software transactional memory you should really, really, really give it a try, since it eliminates a large number of concurrency logic bugs. STM is far and away the most underestimated feature of the Haskell runtime.
wai- the low-level server and API that all server libraries share, with the exception of
scotty- A beginner-friendly server framework analogous to Ruby's Sinatra
spock- Lighter than the "enterprise" frameworks, but more featureful than scotty (type-safe routing, sessions, conn pooling, csrf protection, authentication, etc)
happstack-*- "Enterprise" server frameworks with all the bells and whistles
servant-*- Library for type-safe REST servers and clients that might blow your mind
graphql-api- Implement a GraphQL API
websockets- Standalone websockets client and server
authenticate-*- Shared authentication libraries
ekg-*- Haskell service monitoring
stm- Software-transactional memory
lucid- Haskell DSL for building HTML
karver- Templating libraries
aeson- Parsing and generation of JSON
Some web sites,services, and projects powered by Haskell:
- Facebook's spam filter: Sigma
- IMVU's REST API
- Utrecht's bicycle parking guidance system
- The Perry Bible Fellowship
- ZoomHub (Code)
- PostgREST - Generates a REST API for a Postgres database
- Fighting spam with Haskell - Haskell in production, at scale, at Facebook
- IMVU Engineering - What it's like to use Haskell
- Haskell-based Bicycle Parking Guidance System in Utrecht
- Mio: A High-Performance Multicore IO Manager for GHC
- The Performance of Open Source Applications - Warp
- Optimising Garbage Collection Overhead in Sigma
- instantwatcher.com author comments on rewrite from Ruby to Haskell -  
- A lot of websockets in Haskell - A load test showing that a Haskell server can handle 500K connections in 10 GB of memory. The load tester requires more resources than the server
- Making a Website With Haskell
- Beautiful concurrency - a software-transactional memory tutorial
- The Yesod book
- The Servant tutorial
- Overview of Happstack
Scripting / Command-line applications
Haskell's biggest advantage as a scripting language is that Haskell is the most widely adopted language that supports global type inference. Many languages support local type inference (such as Rust, Go, Java, C#), which means that function argument types and interfaces must be declared but everything else can be inferred. In Haskell, you can omit everything: all types and interfaces are completely inferred by the compiler (with some caveats, but they are minor).
Global type inference gives Haskell the feel of a scripting language while still providing static assurances of safety. Script type safety matters in particular for enterprise environments where glue scripts running with elevated privileges are one of the weakest points in these software architectures.
The second benefit of Haskell's type safety is ease of script maintenance. Many scripts grow out of control as they accrete arcane requirements and once they begin to exceed 1000 LOC they become difficult to maintain in a dynamically typed language. People rarely budget sufficient time to create a sufficiently extensive test suite that exercises every code path for each and every one of their scripts. Having a strong type system is like getting a large number of auto-generated tests for free that exercise all script code paths. Moreover, the type system is more resilient to refactoring than a test suite.
However, the main reason I mark Haskell as mature because the language is also usable even for simple one-off disposable scripts. These Haskell scripts are comparable in size and simplicity to their equivalent Bash or Python scripts. This lets you easily start small and finish big.
Haskell has one advantage over many dynamic scripting languages, which is that Haskell can be compiled into a native and statically linked binary for distribution to others.
Haskell's scripting libraries are feature complete and provide all the niceties that you would expect from scripting in Python or Ruby, including features such as:
- rich suite of Unix-like utilities
- advanced sub-process management
- POSIX support
- light-weight idioms for exception safety and automatic resource disposal
shellmet- scripting libraries (Full disclosure: I authored
cmdargs- command-line argument parsing
haskeline- a complete Haskell implementation of
readlinefor console building
process- low-level library for sub-process management
ansi-terminal- de facto standard cross-platform terminal library (works on Windows as well)
brick- terminal user interfaces (TUIs)
path-io- type safe handling of file paths
wreq- HTTP clients
Some command-line tools written in Haskell:
Haskell data science can take advantage of other data science ecosystems via the
HaskellR is a
Haskell-to-R bridge with Jupyter notebook integration, which lets you take
advantage of the broad R ecosystem while benefiting from the speed and type
safety of Haskell.
Sparkle is a Haskell-to-Spark bridge which lets you
interface with the Spark subset of the Java/Scala data science ecosystem.
However, to get a Mature rating Haskell data science needs to be able to
stand alone without depending on other programming language ecosystems.
If you restrict yourself to just the Haskell ecosystem then choices are more
limited. I'll primarily compare Haskell to Python since that's the data science
ecosystem that I'm more familiar with. Specifically, I'll compare to the
scipy suite of libraries:
The Haskell analog of
NumPy is the
hmatrix library, which provides Haskell
bindings to BLAS, LAPACK.
hmatrix's main limitation is that the API is a bit
clunky, but all the tools are there.
Haskell's charting story is okay. Probably my main criticism of most charting APIs is that their APIs tend to be large, the types are a bit complex, and they have a very large number of dependencies.
Fortunately, Haskell does integrate into IPython so you can use Haskell within an IPython shell or an online notebook. For example, there is an online "IHaskell" notebook that you can use right now located here:
- IHaskell notebook - Click on "Welcome to Haskell.ipynb"
If you want to learn more about how to setup your own IHaskell notebook, visit this project:
The closest thing to Python's
pandas is the
frames library. I haven't used
it that much personally so I won't comment on it much other than to link to
some tutorials in the Educational Resources section.
I'm not aware of a Haskell analog to
SciPy (the library) or
you know of an equivalent Haskell library then let me know.
One Haskell library that deserves honorable mention here is the
library which lets you produce complex data visualizations very easily if
you want something a little bit fancier than a chart. Check out the
project if you have time:
Areas for improvement:
- Smooth user experience and integration across all of these libraries
- Simple types and APIs. The data science programmers I know dislike overly complex or verbose APIs
- Beautiful data visualizations with very little investment
HaskellR- Mix Haskell and R code in Jupyter notebooks
Sparkle- Haskell-to-Spark bridge
cassava- CSV encoding and decoding
hmatrix- BLAS / LAPACK wrapper
Frames- Haskell data analysis tool analogous to Python's
statistics- Statistics (duh!)
Chart-*- Charting library
diagrams-*- Vector graphics library
ihaskell- Haskell backend to IPython
Haskell's numerical programming story is not ready, but steadily improving.
My main experience in this area was from a few years ago doing numerical programming for bioinformatics that involved a lot of vector and matrix manipulation and my rating is largely colored by that experience.
The biggest issues that the ecosystem faces are:
- Really clunky matrix library APIs
- Fickle rewrite-rule-based optimizations
When the optimizations work they are amazing and produce code competitive with C. However, small changes to your code can cause the optimizations to suddenly not trigger and then performance drops off a cliff.
There is one Haskell library that avoids this problem entirely which I believe
holds a lot of promise:
accelerate generates LLVM and CUDA code at runtime
and does not rely on Haskell's optimizer for code generation, which side-steps
accelerate has a large set of supported algorithms that you
can find by just checking the library's reverse dependencies:
However, I don't have enough experience with
accelerate or enough familiarity
with numerical programming success stories in Haskell to vouch for this just
yet. If somebody has more experience then me in this regard and can provide
evidence that the ecosystem is mature then I might consider revising my rating
accelerate-*- GPU programming
vector- high-performance arrays
repa-*- parallel shape-polymorphic arrays
hmatrix-*- Haskell's BLAS / LAPACK wrapper
ad- automatic differentiation
- Exploiting vector instructions with generalized stream fusion
- Type-safe Runtime Code Generation: Accelerate to LLVM
Front-end web programming
ghcjs is the
front-runner, but for a while setting up
ghcjs was non-trivial. Now that
stack build tool supports
ghcjs you can very easily set up a new
project by following these instructions:
One of the distinctive features of
ghcjs compared to other competing
out of the box with
ghcjs because it supports most of
I would also like to mention that there are two Haskell-like languages that
you should also try out for front-end programming:
These are both used in production today and have equally active maintainers and
communities of their own.
purescript in particular is extremely similar to
Areas for improvement:
- There need to be many more educational resources targeted at non-experts explaining how to translate existing front-end programming idioms to Haskell
- There need to be several well-maintained and polished Haskell libraries for front-end programming
- The whole
ghcjsecosystem needs much more documentation. There's not even a basic tutorial on how to actually use
- reflex / reflex-dom - Functional reactive programming library for the front end
- miso a small "isomorphic" front-end framework featuring a virtual-dom, inspired by Elm, Redux and Bobril.
This is sort of a broad area since I'm using this topic to refer to both distributed computation (for analytics) and distributed service architectures. For distributed service architectures Haskell is catching up to its peers with service toolkit libraries, but for distributed computation Haskell still lags behind.
There has been a lot of work in replicating Erlang-like functionality in Haskell through the Cloud Haskell project, not just in creating the low-level primitives for code distribution / networking / transport, but also in assembling a Haskell analog of Erlang's OTP. Work on the higher-level libraries seems to have stopped, but the low-level libraries are still good for distributing computation.
Areas for improvement:
- We need more analytics libraries. Haskell has no analog of
spark. The most we have is just a Haskell wrapper around
- We need a polished consensus library (i.e. a high quality Raft implementation in Haskell)
glue-example- Service toolkit supporting
haxl- Facebook library for efficient batching and scheduling of concurrent data access
distributed-process-*- Haskell analog to Erlang
hadron- Haskell wrapper around
amazonka-*- Auto-generated bindings to the entire Amazon Web Services SDK
gogol-*- Auto-generated bindings to the entire Google Cloud Platform
transient- composable primitives for concurrency / parallelism / distributed computing
Standalone GUI applications
All Haskell GUI libraries are wrappers around toolkits written in other
languages (such as GTK+ or Qt). The last time I checked the
were the most comprehensive, best maintained, and had the best documentation.
The reason for the "Immature" rating is that there still isn't a Haskell binding to a widget toolkit that doesn't have some sort of setup issues with the toolkit.
However, the Haskell bindings to GTK+ have a strongly imperative feel to them.
The way you do everything is communicating between callbacks by mutating
IORefs. Also, you can't take extensive advantage of Haskell's awesome
threading features because the GTK+ runtime is picky about what needs to happen
on certain threads. I haven't really seen a Haskell library that takes this
imperative GTK+ interface and wraps it in a more idiomatic Haskell API.
My impression is that most Haskell programmers interested in applications programming have collectively decided to concentrate their efforts on improving Haskell web applications instead of standalone GUI applications. Honestly, that's probably the right decision in the long run.
Another post that goes into more detail about this topic is this post written by Keera Studios:
Areas for improvement:
- A GUI toolkit binding that is maintained, comprehensive, and easy to use
- Polished GUI interface builders
gi-gtkand various other bindings such as GStreamer audio/video - GTK+ (and more generally, GObject) bindings done right (autogenerated using GObject Introspection, hence
wx- wxWidgets bindings
X11- X11 bindings
threepenny-gui- Framework for local apps that use the web browser as the interface
hsqml- A Haskell binding for Qt Quick, a cross-platform framework for creating graphical user interfaces.
fltkhs- A Haskell binding to FLTK. Easy install/use, cross-platform, self-contained executables.
FregeFX- Frege bindings to Java FX (Frege is essentially the Haskell for the JVM)
typed-spreadsheet- Library for building composable interactive forms
brick- Terminal UI based on vty package
Some example applications:
- Haskell port of the GTK tutorial
- Building pragmatic user interfaces in Haskell with HsQML
- FLTK GUIs, including support for the Fluid visual interface builder
There are two approaches to using machine learning in Haskell:
- Use a Haskell binding to an implementation in another language
- Use a machine learning library implemented in Haskell
You will most likely want to check out Haskell bindings to the
library if you are interested in the first approach:
You will also want to check out Haskell bindings to the
library if you are interested in the first approach:
Also, Tweag.io has released
Sparkle, a Haskell integration with Spark. This
enables the use of MLib from Haskell. MLib is widely used in the industry
for machine learning. Sparkle itself is fairly new.
If you are interested in Haskell implementations of machine learning libraries
then the most promising ones are the
... and the
HLearn-*- Advanced implementations of a subset of machine learning algorithms
grenade- Machine learning library implemented in Haskell with a BLAS/LAPACK backend and a high-level type-based API
tensorflow- Haskell bindings to Google's
arrayfire- Haskell bindings to ArrayFire
ad- Automatic differentiation, used as a substrate for many Haskell machine learning projects
Haskell is a garbage collected language, so Haskell is more appropriate for the scripting / logic layer of a game but not suitable manipulating a large object graph or for implementing a high-performance game engine due to the risk of introducing perceptible pauses due to GC pauses. Also, for simple games you can realistically use Haskell for the entire stack.
Examples of games that could be fully implemented in Haskell:
- Casual games
- Turn-based strategy games
- Adventure games
- Platform / side-scrolling games
- First-person shooter
Examples of games that are difficult to implement at all in Haskell:
- Real-time strategy games
Haskell has SDL and OpenGL bindings, which are actually quite good, but that's about it. You're on your own from that point onward. There is not a rich ecosystem of higher-level libraries built on top of those bindings. There is some work in this area, but I'm not aware of anything production quality or easy to use.
Areas for improvement:
- Improve the garbage collector and benchmark performance with large heap sizes
- Provide higher-level game engines
- Improve distribution of Haskell games on proprietary game platforms
gloss- Simple graphics and game programming for beginners
- Code World - Similar to
gloss, but you can try it in your browser
gl- Comprehensive OpenGL bindings
sdl2- Bindings to the SDL library
SFML- Bindings to the SFML library
quine- Github project with cool 3D demos
GPipe- Type-safe OpenGL API that also lets you embed shader code directly within Haskell. See the GPipe wiki to learn more
ARM processor support
On hobbyist boards like the Raspberry Pi its possible to compile Haskell code with GHC. There are limitations; some libraries have problems on the arm platform, and GHCi only works on newer compilers. Cross compiling doesn't work with template Haskell. Stack and other large projects can take more than 1g of memory to compile.
However, if the Haskell code builds, it runs with respectable performance on these machines.
Arch (Banana Pi)
- installed today from pacman, current versions are GHC 7.10.3 and cabal-install 188.8.131.52
- a compatible version of llvm also installed automatically.
- GHCi passes hello world test; cabal/GHC compiled a modest project normally.
Raspian (Raspberry Pi, pi2, others)
- current version: GHC 7.4, cabal-install 1.14
- GHCi doesn't work.
Debian Jesse (Raspberry Pi 3)
- works with:
llvmversion 3.5.2 or higher. Do not use the
llvm-3.5provided by default in the Jessie package distribution
Arch (Raspberry Pi 2)
- current version 7.8.2, but llvm is 3.6, which is too new.
- downgrade packages for llvm not officially available.
- with llvm downgrade to 3.4, GHC and GHCi work, but problems compiling yesod, scotty.
- compiler crashes, segfaults, etc.
The largest real world Haskell usage of computer vision is LumiGuide, which
powers municipal bicycle detection and guidance systems in Amsterdam. They
OpenCV bindings in their
There are some interesting projects which try to tackle computer vision in a
purely functional manner.
Zef are some
There are Haskell bindings for OpenCV available via
HOpenCV which has bindings
for versions up to
OpenCV 2.0. A fork maintained by Anthony Cowley has bindings
available for versions up to
OpenCV 2.4, but it pretty much stops there.
OpenCV 3.0 has been released, and there are no Haskell bindings
This greatly lags behind using languages that are natively supported by the mobile platform (i.e. Java for Android or Objective-C / Swift for iOS).
However, one route is to compile Haskell to a supported language. For example, you can compile Haskell to Java using Eta to port Haskell games to Android.
Systems / embedded programming
Rating: Bad / Immature (See description)
Since systems programming is an abused word, I will clarify that I mean programs where speed, memory layout, and latency really matter.
Haskell fares really poorly in this area because:
- The language is garbage collected, so there are no latency guarantees
- Executable sizes are large
- Memory usage is difficult to constrain (thanks to space leaks)
- Haskell has a large and unavoidable runtime, which means you cannot easily embed Haskell within larger programs
- You can't easily predict what machine code that Haskell code will compile to
Typically people approach this problem from the opposite direction: they write the low-level parts in C or Rust and then write Haskell bindings to the low-level code.
It's worth noting that there is an alternative approach which is Haskell DSLs that are strongly typed that generate low-level code at runtime. This is the approach championed by the company Galois.
ivory- DSL for generating embedded programs
copilot- Stream DSL that generates C code
improve- High-assurance DSL for embedded code that generates C and Ada
Common Programming Needs
Rating: Best in class
Haskell is unbelievably awesome for maintaining large projects. There's nothing that I can say that will fully convey how nice it is to modify existing Haskell code. You can only appreciate this through experience.
When I say that Haskell is easy to maintain, I mean that you can easily approach a large Haskell code base written by somebody else and make sweeping architectural changes to the project without breaking the code.
You'll often hear people say: "if it compiles, it works". I think that is a bit of an exaggeration, but a more accurate statement is: "if you refactor and it compiles, it works". This lets you move fast without breaking things.
Most statically typed languages are easy to maintain, but Haskell is on its own level for the following reasons:
- Strong types
- Global type inference
- Type classes
The latter three features are what differentiate Haskell from other statically typed languages.
If you've ever maintained code in other languages you know that usually your test suite breaks the moment you make large changes to your code base and you have to spend a significant amount of effort keeping your test suite up to date with your changes. However, Haskell has a very powerful type system that lets you transform tests into invariants that are enforced by the types so that you can statically eliminate entire classes of errors at compile time. These types are much more flexible than tests when modifying code and types require much less upkeep as you make large changes.
The Haskell community and ecosystem use the type system heavily to "test" their applications, more so than other programming language communities. That's not to say that Haskell programmers don't write tests (they do), but rather they prefer types over tests when they have the option.
Global type inference means that you don't have to update types and interfaces as you change the code. Whenever I do a large refactor the first thing I do is delete all type signatures and let the compiler infer the types and interfaces for me as I go. When I'm done refactoring I just insert back the type signatures that the compiler infers as machine-checked documentation.
Type classes also assist refactoring because the compiler automatically infers type class constraints (analogous to interfaces in other languages) so that you don't need to explicitly annotate interfaces. This is a huge time saver.
Laziness deserves special mention because many outsiders do not appreciate how laziness simplifies maintenance. Many languages require tight coupling between producers and consumers of data structures in order to avoid wasteful evaluation, but laziness avoids this problem by only evaluating data structures on demand. This means that if your refactoring process changes the order in which data structures are consumed or even stops referencing them altogether you don't need to reorder or delete those data structures. They will just sit around patiently waiting until they are actually needed, if ever, before they are evaluated.
Rating: Best in class
I give Haskell a "Best in class" rating because Haskell's concurrency runtime performs as well or better than mainstream languages and is significantly easier to use due to the runtime support for software-transactional memory.
The best explanation of Haskell's threading module is the documentation in
Concurrency is "lightweight", which means that both thread creation and context switching overheads are extremely low. Scheduling of Haskell threads is done internally in the Haskell runtime system, and doesn't make use of any operating system-supplied thread packages.
In Haskell, all I/O is non-blocking by default, so for example a web server will just spawn one lightweight thread per connection and each thread can be written in an ordinary synchronous style instead of nested callbacks like in Node.js.
The best way to explain the performance of Haskell's threaded runtime is to give hard numbers:
- The Haskell thread scheduler can easily handle millions of threads
- Each thread requires 1 kb of memory, so the hard limitation to thread count is memory (1 GB per million threads).
- Haskell channel overhead for the standard library (using
TQueue) is on the order of one microsecond per message and degrades linearly with increasing contention
- Haskell channel overhead using the
unagi-chanlibrary is on the order of 100 nanoseconds (even under contention)
MVar(a low-level concurrency communication primitive) requires 10-20 ns to add or remove values (roughly on par with acquiring or releasing a lock in other languages)
Haskell also provides software-transactional memory, which allows programmers build composable and atomic memory transactions. You can compose transactions together in multiple ways to build larger transactions:
- You can sequence two transactions to build a larger atomic transaction
- You can combine two transactions using alternation, falling back on the second transaction if the first one fails
- Transactions can retry, rolling back their state and sleeping until one of their dependencies changes in order to avoid wasteful polling
A few other languages provide software-transactional memory, but Haskell's implementation has two main advantages over other implementations:
- The type system enforces that transactions only permit reversible memory modifications. This guarantees at compile time that all transactions can be safely rolled back.
- Haskell's STM runtime takes advantage of enforced purity to improve the efficiency of transactions, retries, and alternation.
Haskell is also the only language that supports both software transactional memory and non-blocking I/O.
stm- Software transactional memory
unagi-chan- High performance channels
async- Futures library
streamly- A streaming library offering high performance concurrency
- Parallel and Concurrent Programming in Haskell
- Parallel and Concurrent Programming in Haskell - Software transactional memory
- Beautiful concurrency - a software-transactional memory tutorial
- Performance numbers for primitive operations - Latency timings for various low-level operations
Types / Type-driven development
Rating: Best in class
Haskell definitely does not have the most advanced type system (not even close if you count research languages) but out of all languages that are actually used in production Haskell is probably at the top. Idris is probably the closest thing to a type system more powerful than Haskell that has a realistic chance of use in production in the foreseeable future.
The killer features of Haskell's type system are:
- Type classes
- Global type and type class inference
- Light-weight type syntax
Haskell's type system really does not get in your way at all. You (almost) never need to annotate the type of anything. As a result, the language feels light-weight to use like a dynamic language, but you get all the assurances of a static language.
Many people are familiar with languages that support "local" type inference (like Rust, Java, C#), where you have to explicitly type function arguments but then the compiler can infer the types of local variables. Haskell, on the other hand, provides "global" type inference, meaning that the types and interfaces of all function arguments are inferred, too. Type signatures are optional (with some minor caveats) and are primarily for the benefit of the programmer.
Here is an example of writing a function without any types or interfaces at all and asking the compiler to infer them for you:
>>> let addAndShow x y = show (x + y) >>> :type addAndShow addAndShow :: (Num a, Show a) => a -> a -> String
This really benefits projects where you need to prototype quickly but refactor painlessly when you realize you are on the wrong track. You can leave out all type signatures while prototyping but the types are still there even if you don't see them. Then when you dramatically change course those strong and silent types step in and keep large refactors painless.
Some Haskell programmers use a "type-driven development" programming style, analogous to "test-driven development":
- they specify desired behavior as a type signature which initially fails to type-check (analogous to adding a test which starts out "red")
- they create a quick and dirty solution that satisfies the type-checker (analogous to turning the test "green")
- they improve on their initial solution while still satisfying the type-checker (analogous to a "red/green refactor")
"Type-driven development" supplements "test-driven development" and has different tradeoffs:
- The biggest disadvantage of types is that they don't test as many things as full-blown tests, because Haskell is not (yet) dependently typed
- The biggest advantage of types is that they can prove the complete absence of programming errors that you can encode in the type system, whereas tests do not typically exercise every possible code path
- Type-checking is much faster than running tests
- Type error messages are informative: they explain what went wrong
- Type-checking never hangs and never gives flaky results
Haskell also provides the "Typed Holes" extension, which lets you add an
underscore (i.e. "
_") anywhere in the code whenever you don't know what
expression belongs there. The compiler will then tell you the expected type of
the hole and suggest terms in scope with related types that you can use to fill
There is also a newly added "Liquid Haskell" extension under development which you can use to program with "refinement types". These types enrich Haskell's type system with the ability to decorate type signatures with logical predicates and arithmetic, and increases the number of invariants that you can encode at the type level.
- Learn you a Haskell - Types and type classes
- Learn you a Haskell - Making our own types and type classes
- Typed holes
- Partial type signatures proposal
- Programming with refinement types - Very extensive tutorial on how to use Liquid Haskell with interactive examples you can run in your browser
- What exactly makes the Haskell type system so revered (vs say, Java)?
- Difference between OOP interfaces and FP type classes
- Compile-time memory safety using Liquid Haskell - post illustrating an example use case for refinement types
Parsing / Pretty-printing
Rating: Best in class
Haskell parsing is sooooooooooo slick. Recursive descent parser combinators are far-and-away the most popular parsing paradigm within the Haskell ecosystem, so much so that people use them even in place of regular expressions. I strongly recommend reading the "Monadic Parsing in Haskell" functional pearl linked below if you want to get a feel for why parser combinators are so dominant in the Haskell landscape.
If you're not sure what library to pick, I generally recommend the
library as a default well-rounded choice because it strikes a decent balance
between ease-of-use, performance, good error messages, and small dependencies
(since it ships with GHC). There is also the
megaparsec library, which is
modern and improved version of
attoparsec deserves special mention as an extremely fast backtracking parsing
library. The speed and simplicity of this library will blow you away. The
main deficiency of
attoparsec is the poor error messages.
The pretty-printing front is also excellent. Academic researchers just really love writing pretty-printing libraries in Haskell for some reason.
parsec- Best overall "value"
megaparsec- Modern, actively maintained fork of
attoparsec- Extremely fast backtracking parser
Earley- Earley parsing embedded within the Haskell language. Parses all context-free grammars, even ambiguous ones, with no need to left factor. Returns all valid parses.
trifecta- Best error messages (
parsers- Interface compatible with
trifectawhich lets you easily switch between them. People commonly use this library to begin with
parsec(for better error messages) then switch to
attoparsecwhen done for performance
yaccbut with Haskell integration
Domain-specific languages (DSLs)
Haskell rocks at DSL-building. While not as flexible as a Lisp language I would venture that Haskell is the most flexible of the non-Lisp languages. You can overload a large amount of built-in syntax for your custom DSL.
The most popular example of overloaded syntax is
do notation, which you can
overload to work with any type that implements the
Monad interface. This
syntactic sugar for
Monads in turn led to a huge overabundance of
However, there are lesser known but equally important things that you can overload, such as:
- numeric and string literals
- list comprehensions
- numeric operators
There are a few places where Haskell is the clear leader among all languages:
- property-based testing
- mocking / dependency injection
QuickCheck is the gold standard which all other property-based
testing libraries are measured against. The reason
QuickCheck works so
smoothly in Haskell is due to Haskell's type class system and purity. The type
class system simplifies automatic generation of random data from the input type
of the property test. Purity means that any failing test result can be
automatically minimized by rerunning the check on smaller and smaller inputs
QuickCheck identifies the corner case that triggers the failure.
Mocking is another area where Haskell shines because you can overload almost all built-in syntax, including:
- numeric literals
- string literals
Haskell programmers overload this syntax (particularly
do notation) to write
code that looks like it is doing real work:
example = do str <- readLine putLine str
... and the code will actually evaluate to a pure syntax tree that you can use to mock in external inputs and outputs:
example = ReadLine (\str -> PutStrLn str (Pure ()))
Haskell also supports most testing functionality that you expect from other languages, including:
- standard package interfaces for testing
- unit testing libraries
- test result summaries and visualization
QuickCheck- property-based testing
doctest- tests embedded directly within documentation
free- Haskell's abstract version of "dependency injection"
hspec- Testing library analogous to Ruby's RSpec
HUnit- Testing library analogous to Java's JUnit
tasty- Combination unit / regression / property testing library
hedgehog- property-based testing with integrated shrinking
HTF- Preprocessor based unit testing with various output formats
Data structures and algorithms
Haskell primarily uses persistent data structures, meaning that when you "update" a persistent data structure you just create a new data structure and you can keep the old one around (thus the name: persistent). Haskell data structures are immutable, so you don't actually create a deep copy of the data structure when updating; any new structure will reuse as much of the original data structure as possible.
The Notable libraries sections contains links to Haskell collections libraries that are heavily tuned. You should realistically expect these libraries to compete with tuned Java code. However, you should not expect Haskell to match expertly tuned C++ code.
The selection of algorithms is not as broad as in Java or C++ but it is still pretty good and diverse enough to cover the majority of use cases.
vector- High-performance arrays
accelerate-*- GPU programming
repa-*- parallel shape-polymorphic arrays
discrimination- Efficient linear-time sorting for user-defined datatypes
This boils down exclusively to the
criterion library, which was done so well
that nobody bothered to write a competing library. Notable
- Detailed statistical analysis of timing data
- Beautiful graph output: (Example)
- High-resolution analysis (accurate down to nanoseconds)
- Customizable HTML/CSV/JSON output
- Garbage collection insensitivity
Haskell's Unicode support is excellent. Just use the
libraries, which provide a high-performance, space-efficient, and easy-to-use
API for Unicode-aware text operations.
Note that there is one big catch: the default
String type in Haskell is
inefficient. You should always use
Text whenever possible.
Haskell's streaming ecosystem is mature. Probably the biggest issue is that there are too many good choices (and a lot of ecosystem fragmentation as a result), but each of the streaming libraries listed below has a sufficiently rich ecosystem including common streaming tasks like:
- Network transmissions
- External process pipes
- High-performance streaming aggregation
- Concurrent streams
- Incremental parsing
streamly- Stream programming libraries (Full disclosure: I authored
pipesand wrote the official
machines- Networked stream transducers library
- The official
- The official
- The official
- A benchmark of popular streaming libraries
Serialization / Deserialization
Haskell's serialization libraries are reasonably efficient and very easy to use. You can easily automatically derive serializers/deserializers for user-defined data types and it's very easy to encode/decode values.
Haskell's serialization does not suffer from any of the gotchas that object-oriented languages deal with (particularly Java/Scala). Haskell data types don't have associated methods or state to deal with so serialization/deserialization is straightforward and obvious. That's also why you can automatically derive correct serializers/deserializers.
Serialization performance is pretty good. You should expect to serialize data at a rate between 100 Mb/s to 1 Gb/s with careful tuning. Serialization performance still has about 3x-5x room for improvement by multiple independent estimates. See the "Faster binary serialization" link below for details of the ongoing work to improve the serialization speed of existing libraries.
- Benchmarks of several popular serialization libraries
- Faster binary serialization / Better, faster binary serialization - Slides on serialization efficiency improvements
Support for file formats
Haskell supports all the common domain-independent serialization formats (i.e. XML/JSON/YAML/CSV). For more exotic formats Haskell won't be as good as, say, Python (which is notorious for supporting a huge number of file formats) but it's so easy to write your own quick and dirty parser in Haskell that this is not much of an issue.
aeson- JSON encoding/decoding
sv- CSV encoding/decoding
yaml- YAML encoding/decoding
HsYAML- pure Haskell YAML 1.2 parser
xml- XML encoding/decoding
tomland- TOML encoding/decoding
This rating is based entirely on the recent release of the
stack package tool
by FPComplete which greatly simplifies package installation and dependency
management. This tool was created in response to a broad survey of existing
Haskell users and potential users where
cabal-install was identified as the
single greatest issue for professional Haskell development.
stack tool is not just good by Haskell standards but excellent even
compared to other language package managers. Key features include:
- Excellent project isolation (including compiler isolation)
- Global caching of shared dependencies to avoid wasteful rebuilds
- Easily add local repositories or remote GitHub repositories as dependencies
stack is also powered by Stackage, which is a very large Hackage mono-build
that ensures that a large subset of Hackage builds correctly against each
other and automatically notifies package authors to fix or update libraries
when they break the mono-build. Periodically this package set is frozen as a
Stackage LTS release which you can supply to the
stack tool in order to
select dependencies that are guaranteed to build correctly with each other.
Also, if all your projects use the same or similar LTS releases they will
benefit heavily from the shared global cache.
Haskell has decent logging support. That's pretty much all there is to say.
fast-logger- High-performance multicore logging system
hslogger- Logging library analogous to Python's
monad-logger- add logging with line numbers to your monad stack. Uses fast-logger under the hood.
katip- Structured logging
log- Logging system with ElasticSearch, PostgreSQL and stdout sinks.
co-log- Composable contravariant comonadic logging library.
Haskell provides two tools for automatic code formatting:
stylish-haskell- Less opinionated code formatting tool that mostly formats imports, language extensions, and data type definitions
"Haskell Programming from first principles" has been published. I highly recommend it, for the following reasons:
- The book does not assume any prior programming experience
- The book does not have any conceptual gaps or out-of-order dependencies
- The book is extremely comprehensive
- Haskell Programming from first principles - The best Haskell resource to learn from. The book costs $60, but it's worth the price.
- Get Programming with Haskell- An approachable and thorough introduction to Haskell and functional programming. A capstone project at the end of each unit.
- Haskell Wikibook — One of the highest quality among Wikimedia's Wikibooks, which starts from zero, with no assumption of previous programming experience
- How I Start - Haskell — Example development environment and workflow
- Happy Learn Haskell Tutorial - An example-driven book for complete beginners, with interesting cartoons
- Learn You a Haskell for Great Good — A beginning Haskell book
- Real world Haskell — A book that contains several practical cookbook-style examples. Many code examples are out of date, but the book is still useful
- Parallel and Concurrent Programming in Haskell — Exactly what the title says
- Thinking Functionally with Haskell — Book targeting people who are interested in Haskell in order to "think differently"
- Haskell wiki — Grab bag of Haskell-related information with wide variation in quality. Excels at large lists of resources or libraries if you don't mind sifting through stale or abandoned entries
- The Haskell 2010 Report — The Haskell language specification
- Queensland FP Lab - FP Course - An "interactive" course ran within GHCI; beginner-safe, smoothly ramps up introduction of content.
Databases and data stores
This is is not one of my areas of expertise, but what I do know is that Haskell
has bindings to most of the open source databases and datastores such as MySQL,
Postgres, SQLite, Cassandra, Redis, DynamoDB and MongoDB. However, I haven't really
evaluated the quality of these bindings other than the
library, which is the only one I've personally used and was decent as far as I
The "Immature" ranking is based on the lack of bindings to commercial databases like Microsoft SQL server and Oracle. So whether or not Haskell is right for you probably depends heavily on whether there are bindings to the specific data store you use.
mysql-simple- MySQL bindings
postgresql-simple- Postgres bindings
persistent- Database-agnostic ORM that supports automatic migrations
opaleye- type-safe APIs for building well-formed SQL queries
acid-state- Simple ACID data store that saves Haskell data types natively
aws- Bindings to Amazon DynamoDB
hedis- Bindings to Redis
groundhog- A nice datatype to relational mapping library, similar to ORMs
hasql- An efficient PostgreSQL driver and a flexible mapping API based on the binary protocol
The main Haskell debugging features are:
- Memory and performance profiling
- Stack traces
- Source-located errors, using the
- Breakpoints, single-stepping, and tracing within the GHCi REPL
printf-style tracing using
The two reasons I still mark debugging "Immature" are:
- GHC's stack traces require profiling to be enabled
- There is only one IDE that I know of (
leksah) that integrates support for breakpoints and single-stepping and
leksahstill needs more polish
ghc-7.10 also added preliminary support for DWARF symbols which allow support
gdb-based debugging and
perf-based profiling, but there is still more
work that needs to be done. See the following page for more details:
- GHC Manual - Profiling chapter - Read the whole thing; you will thank me later
- Debugging runtime options - See the
+RTS -xcflag which adds stack traces to all exceptions (requires profiling enabled)
GHC.Stack- Programmatic access to the call stack
- Pinpointing space leaks in big programs
- Real World Haskell - Profiling and Optimization
- The GHCi Debuggger - Manual for GHCi-based breakpoints and single-stepping
- Parallel and Concurrent Programming in Haskell - Debugging, Tuning, and Interfacing with Foreign Code - Debugging concurrent programs
- Haskell wiki - ThreadScope
I give Haskell an "Immature" rating primarily due to poor user experience on Windows:
- Most Haskell tutorials assume a Unix-like system
- Several Windows-specific GHC bugs
- Poor IDE support (Most Windows programmers don't use a command-line editor)
This is partly a chicken-and-egg problem. Haskell has many Windows-specific issues because it has such a small pool of Windows developers to contribute fixes. Most Haskell developers are advised to use another operating system or a virtual machine to avoid these pain points, which exacerbates the problem.
The situation is not horrible, though. I know because I do half of my Haskell programming on Windows in order to familiarize myself with the pain points of the Windows ecosystem and most of the issues affect beginners and can be worked around by more experienced developers. I wouldn't say any individual issue is an outright dealbreaker; it's more like a thousand papercuts which turn people off of the language.
If you're a Haskell developer using Windows, I highly recommend the following installs to get started quickly and with as few issues as possible:
- Git for Windows - A Unix-like
command-line environment bundled with
gitthat you can use to follow along with tutorials
- MinGHC - Use this for project-independent Haskell experimentation
- Stack - Use this for project development
Additionally, learn to use the command line a little bit until Haskell IDE support improves. Plus, it's a useful skill in general as you become a more experienced programmer.
For Mac, the recommended installation is:
- Haskell for Mac - A self-contained relocatable GHC build for project-independent Haskell experimentation
- Stack - Use this for project development
For other operating systems, use your package manager of choice to install
- Haskell wiki - Windows - Windows startup guide for Haskell
Hot code loading
Haskell does provide support for hot code loading, although nothing in the same ballpark as in languages like Clojure.
There are two main approaches to hot code loading:
- Compiling and linking object code at runtime (i.e. the
- Recompiling the entire program and then reinitializing the program with the
program's saved state (i.e. the
You might wonder how Cloud Haskell sends code over the wire and my understanding is that it doesn't. Any function you wish to send over the wire is instead compiled ahead of time on both sides and stored in a shared symbol table which each side references when encoding or decoding the function.
Haskell does not let you edit a live program like Clojure does so Haskell will probably never be "Best in class" short of somebody releasing a completely new Haskell compiler built from the ground up to support this feature. The existing Haskell tools for hot code swapping seem as good as they are reasonably going to get, but I'm waiting for commercial success stories of their use before rating this "Mature".
halive library has the best hot code swapping demo by far:
rapid- Code reloading within
ghcithat persists state across reloads
hint- Runtime compilation and linking
halive- Program reinitialization with saved state
The best supported editors at the moment appear to be:
- Emacs (via
- Spacemacs (via haskell-layer)
- Vim (via
- Atom (via
- IntelliJ IDEA (http://rikvdkleij.github.io/intellij-haskell/)
I am not the best person to review this area since I do not use an IDE myself. I'm basing this "Immature" rating purely on what I have heard from others. The impression I get is that the biggest pain point is that Haskell IDEs, IDE plugins, and low-level IDE tools keep breaking. The above three editors are the ones that have historically had the fewest setup issues.
Most of the Haskell early adopters have been
emacs users so
those editors have gotten the most love. Support for more traditional IDEs
has improved recently with Haskell plugins for Atom, IntelliJ, and also the
Also, if you have a Mac then the "Haskell for Mac" development environment is supposed to work really well for learning since it provides an interactive and visual playground for exploring the code.
hoogle— Type-based function search
hayoo— Haskell function search covering more libraries
hlint— Code linter
ghc-mod— editor agnostic tool that powers many IDE-like features
ghcid— lightweight background type-checker that triggers on code changes
codex— Tags file generator for cabal project dependencies.
hdevtools— Persistent GHC-powered background server for development tools
ghc-imported-from— editor agnostic tool that finds Haddock documentation page for a symbol
haskell-tools- Refactoring tool + library
ghcide- A library for building Haskell IDE tooling
stan- Haskell Static Analyser
Vim and Neovim Plugins:
haskell-vim-now- a highly customized
.vimrcwith some 20 plugins and key bindings configured to work with Haskell.
- haskell-ide-engine (see below) via LanguageClient-neovim
The two plugins provide different sets of features.
Many plugins installed by
haskell-vim-now can be used with
as well, but there is no ready made config/installation script yet.
haskell-mode— Umbrella project for Haskell
intero- Intero, a complete interactive development program for Haskell (another all-in-the-one solution for
structured-haskell-mode- structural editing based on Haskell syntax for
haskell-ide-engine(see below) via
Language Service Protocol:
The recent movement is to migrate all the editor plugins for Haskell to the Microsoft's Language Protocol (LSP) which allows to support many different editors with one unified plugin. The server part of the protocol is in
haskell-ide-engine (not yet on hackage). The client part is different for different editors.
The following editors are tested. See haskell-ide-engine/README.md for installation instructions:
- Visual Studio Code / VSCode
- neovim / vim7
- Sublime Text
More editors probably work, but there is no installation instruction yet: Eclipse, Eclipse Che, Microsoft Monaco,IntelliJ / JetBrains IDEs, Emacs, Theia, Spyder IDE, Oni. See an up to date list of "language clients" at http://langserver.org/
Note that the LSP protocol specification currently only covers navigation/browsing/references, types/symbol info, refactoring, linting and completion/intellisense aspects of IDE. Project management, building, syntax highlighting and debugging are not covered yet, so you need separate editor-specific support for that. Sometimes when you install HIE as per instruction, these components are bundled as well, but sometimes they don't.
Non-LSP IDE plugins:
- Atom (the
- IntelliJ IDEA (Intellij-Haskell http://rikvdkleij.github.io/intellij-haskell/ or Haskforce http://haskforce.com/)
- Visual Studio Code (the
Haskell Syntax Highlightingextension)
- A Vim + Haskell Workflow
- Survey: Which Haskell development tools are you using that make you a more productive Haskell programmer?
- Aaron Levin
- Alois Cochard
- Ben Kovach
- Benno Fünfstück
- Carlo Hamalainen
- Chris Allen
- Curtis Gagliardi
- David Howlett
- David Johnson
- Edward Cho
- Greg Weber
- Gregor Uhlenheuer
- Juan Pedro Villa Isaza
- Kazu Yamamoto
- Kevin Cantu
- Kirill Zaborsky
- Liam O'Connor-Davis
- Luke Randall
- Marcio Klepacz
- Mitchell Rosen
- Nicolas Kaiser
- Oliver Charles
- Pierre Radermecker
- Rodrigo B. de Oliveira
- Stephen Diehl
- Tim Docker
- Tran Ma
- Yuriy Syrovetskiy