Haskell is a statically typed pure functional programming language. It is based on highly sound academic theory and principal. Haskell has pioneered many modern concepts in functional programming such as monads, currying and advanced type inference.

Haskell can be either compiled or interpreted depending on the programming environment being used.

Why would I learn this language?

Haskell is an advanced programming language based on rigorous theory. It has a strict type system that allows for many programming errors to be caught at compile time and has a functional design that makes concurrency and parallelism relatively easy.

Knowledge of higher order functions can provide the programmer with unique ways of solving certain problems, and lazy evaluation can make certain kinds of algorithms possible that aren't possible to implement in other languages (without modification of the algorithm)

Starting Points

Try Haskell
An online interactive tutorial.
Learn You a Haskell for Great Good!
Comprehensive Set Tutorials — suitable for introduction to programming.
Learn Haskell in 10 minutes
A quick introduction to programming with Haskell suitable for those already familiar with programming.
Haskell: Batteries Included
Set of resources for learning and teaching Haskell.

Example Code

The following is an example of the Fizz Buzz problem. You can run and edit this program here.

fb :: Integer -> String
fb n
  | mod n 3 == 0 && mod n 5 == 0  = "FizzBuzz"
  | mod n 3 == 0                  = "Fizz"
  | mod n 5 == 0                  = "Buzz"
  | otherwise                     = show n

main = do 
  putStrLn $ unlines (map fb [1..100])

The following is an example of the 100 doors problem. You can run and edit this program here.

-- A data structure for a door, either Open or Closed:
data Door = Open | Closed deriving Show

-- A function named 'toggle' that will open a closed door or close an opened door:
toggle :: Door -> Door
toggle Open   = Closed
toggle Closed = Open

-- Get the final state of the nth door:
final :: Int -> Door
final n = foldr toggleIfMultiple Closed [1..n]
 where toggleIfMultiple m door = if n `rem` m == 0 then toggle door else door

-- Print a message reporting the final state each of our 100 doors:
main = putStr (concatMap report [1..100])
 where report n = "Door " ++ show n ++ " is " ++ show (final n) ++".\n"

Further Reading

comments powered by Disqus