
HHG
“Haskell is a general purpose, purely functional programming language incorporating many recent innovations in programming language design.”
— Haskell 98 Report
Here, “pure” means that the language has no side-effects. How this is possible will be explained shortly.
Haskell provides
Haskell also has a rich set of primitive data types including
Of course, we begin with “Hello, World!”
main = putStrLn "Hello, World!"
Simple interaction
main = do putStrLn "What is 2 + 2?"
x <- readLn
if x == 4
then putStrLn "You're right!"
else putStrLn "You're wrong!"
module Main where
factorial n = if n == 0
then 1
else n * factorial (n - 1)
main = do putStrLn "What is 5! ?"
x <- readLn
if x == factorial 5
then putStrLn "You're right!"
else putStrLn "You're wrong!"
factorial :: Integer -> Integer
factorial n = if n == 0
then 1
else n * factorial (n - 1)
| Characteristic | Haskell | Python |
|---|---|---|
| Paradigm | Functional | Imperative |
| Object-oriented? | No - uses type classes instead | Yes |
| Data types | Static | Dynamic |
| Evaluation | Lazy | Strict |
| Polymorphism | Yes | Duck-typing |
Haskell allows the programmer to define new data types. However, Haskell is not object-oriented. Instead it provides type classes which enable many of the same features without the strict hierarchy of objects.
Examples of type definitions:
data Bool = False | True deriving
(Read, Show, Eq,
Ord, Enum, Bounded)
data [a] = [] | a : [a] deriving (Eq, Ord)
type String = [Char]
Example of type class definition:
The Eq type class is used by almost all types.
class Eq a where
(==), (/=) :: a -> a -> Bool
x /= y = not (x == y)
x == y = not (x /= y)
It is only necessary to define one of == and /=. The other definition can be inferred by negation.

Haskell classes
“Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot.”
— Eric Raymond, “How to Become a Hacker”
The same can be said for Haskell.
Haskell is harder to learn than Python or most other languages.
However, the main reason that Haskell is harder to learn is that there is so much more power to it than most other languages.
Haskell learners often have difficulty with
Functional programming style
Yes!
Any questions?