Haskell is a purely functional programming language featuring strong static typing, lazy evaluation, extensive parallelism and concurrency support, and unique abstraction capabilities.
Haskell is a purely functional programming language. An open-source product of more than twenty years of research, it allows rapid development of robust, concise, correct software. With strong support for integration with other languages, built-in concurrency and parallelism, debuggers, profilers, rich libraries, and an active community, Haskell makes it easier to produce flexible, maintainable, high-quality software.
Checklist
To avoid answering the same questions over and over again, please check the list of interesting questions and this checklist:
Mixing tabs and spaces
A lot of errors mentioning some sort of parse error on input...
are caused by the user mixing spaces and tabs in the indentation, so please check that is not the case. Also, you should probably set up your editor to convert tabs into spaces.
Type-checking problems at compilation
While Haskell's type system is very powerful, its behavior can sometimes be confusing. The more explicit type signatures you add, the less possibilities there are for the compiler to deduce absurd relations. Type signatures also make questions more understandable, because it's obvious what you want a function to do.
Performance issues
In case of performance issues, please make sure that you compile your code with optimizations enabled. Passing -O2
to the compiler makes many performance issues go away. The GHC interpreter is noticeably slower than running the binary outputted from GHC's compiler.
It can also be helpful to compile with -Wall
in order to observe (among other useful things) places where numeric types are being defaulted to the arbitrary precision Integer
type, so that you can consider whether you get away with using the more efficient fixed precision Int
type.
It is also important to know which version of the compiler and libraries you use. Providing those pieces of information may significantly decrease the time it takes the community to answer your question.
Many beginner performance issues stem from a misunderstanding of what lists are, and how they can be used effectively. In particular, they are not arrays, but have the same structure as linked lists in imperative languages:
data List a = Cons a (List a)
| Empty
Understanding that [a]
is a nested (recursive) algebraic data type is important for supporting an intuition for the efficiency of operations like (:)
vs (++)
, (!!)
, length
, etc.
Idiomatic and efficient use of lists involve composing functions like zip
, map
, filter
, foldr
, take
, etc. many of which allow the intermediate lists to be eliminated entirely.
The Prelude's String
type is implemented in terms of lists:
type String = [Char]
This is a very convenient representation but is quite memory inefficient, and unsuitable for text processing where performance is a concern. Instead the text
library should be used.
The bytestring
is a similarly fast and efficient high-level interface around a string (or stream) of bytes. The Data.ByteString.Char8
module can be used for an efficient representation of a small subset of unicode, for instance where only ASCII text is expected.
"What is function foo
/ operator #$*
?"
Haskell's syntax is very simple, in the sense that everything (apart from the few keywords) is just a library function1, including all infix operators. Those functions can easily be searched for,
- Hayoo searches identifiers and signatures throughout the entire Hackage database.
- Hoogle also searches for identifiers and signatures, but only works when the function comes from a known package.
Please try these engines first before asking a question like this or this or this.
"What library should I use for <thing>
?"
These types of questions are generally off-topic, but here are some useful resources:
- The "State of the Haskell Ecosystem" collaborative document
- Browsing the list of packages on hackage and looking at download counts and reverse dependencies as a measure of popularity/maturity.
Getting started
- Download the Haskell Platform for your platform. This includes the state-of-the-art Glasgow Haskell Compiler (GHC) and common developer tools and libraries.
- Check out these Stack Overflow questions with links to popular websites and tutorials:
- Have fun, and ask questions!
Interesting questions/answers
- What is a monad?
- Why are side-effects modeled as monads in Haskell?
- foldl versus foldr behavior with infinite lists
- What are practical uses of applicative style?
- Haskell: How does non-strict and lazy differ?
- Derivation of a monad transformer (answer to Could i be using a bind/fmap here)
- Comparing Haskell's Snap and Yesod web frameworks
- Asymmetry in the bind function
- What does the forall keyword in Haskell/GHC do?
- What is Weak Head Normal Form?
- Difference between . (dot) and $ (dollar sign)?
- Large scale design in Haskell
- What's the status of multicore programming in Haskell?
- What's so bad about Lazy I/O?
- Which Haskell (GHC) extensions should users use/avoid?
- Explanation of traverse function in Haskell
- Explanation of evaluate function in Haskell
- Composing Function composition: Intuition behind (.).(.)
- How to approach laziness at design time
- Function privacy and unit testing in Haskell
- Explanation of Data Constructor, Type Constructor, Type Variable and Kinds
- Benefits of Applicative parsing over Monadic parsing
- Memory footprint of Haskell data types
- Haskell equivalent of OOP ideas
- Reasoning about lazy sequences
- IO, Strict Evaluation and WHNF
- What is spine strictness
- Theoretical basis for Existential types
- Understanding function evaluation in Haskell
- Understanding Lazy evaluation
- lenses, fclabels, data-accessor - what are the differences
- Explanation of existential and universally quantified types in Haskell
- RankNTypes and Polykinds
- Algorithm behind pointfree
- Where do values fit in Category of Hask
- Why is Haskell missing obvious typeclasses?
- Why are difference lists more efficient than regular concatenation?
Notable Haskell Implementations
- GHC: Glasgow Haskell Compiler, an optimizing compiler for Haskell.
- UHC: a Haskell implementation from Utrecht University.
- Hugs: a once-popular Haskell interpreter that is no longer maintained. Most people now use GHCi for interactive development.
Community
Other places for discussing Haskell, beyond the question & answer format of Stack Overflow:
- Wiki: HaskellWiki
- Mailing lists: see here
- reddit: /r/haskell
- Google+: Haskell Community
- IRC: #haskell on freenode
- Slack: Functional Programming Slack
Free Haskell Programming Books
- Learn You a Haskell for Great Good
- Real World Haskell
- Haskell Wikibook
- Programming in Haskell
- Parallel and Concurrent Programming in Haskell
- The Haskell Road to Logic, Maths, and Programming
- The Implementation of Functional Programming Languages
Haskell Programming Books
Haskell papers
The following list is courtesy of Gangadhar:
- Why Functional Programming Matters
- History of Haskell
- Watch videos on Channel9 related to FP - though not always academic
- Follow LtU
- Did not read the FP journal - but it can have information of use to you
- Monad Reader
- The paper on composing contracts by Simon Peyton Jones is a good read, as is pretty much everything from his papers and those of Philip Wadler.
- Typing Haskell in Haskell – implementation of basic Haskell typesystem in Haskell by Simon Peyton Jones
More information
1Technically, it would be more correct to say everything is a library value, because something like a numerical constant or an IO
action is not actually a function.