Waste less time on Facebook — follow Brilliant.

[MOOC] Introduction to Programming in Haskell

I am volunteering as the teaching assistant of a MOOC in Introduction to Programming in Haskell. I'd be glad to see members from the Brilliant community join.

Why Haskell?

  • Haskell is a functional language. This means, problems in Haskell are solved by describing what the problem is and how it can be solved by composing smaller logical units, called functions, together. This is as opposed to the usual sense of programming where programs are a bunch of instructions.

Consider the following implementation of Quicksort in Haskell:

quicksort :: Ord a => [a] -> [a]
quicksort []     = []
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
        lesser  = filter (< p) xs
        greater = filter (>= p) xs
  • Haskell is lazy. Haskell only evaluates an expression when needed. This means we can do cool stuff like implement infinite lists.

Consider the following implementation of an infinite list of primes Sieve of Eratosthenes:

primes = filterPrime [2..] 
  where filterPrime (p:xs) = 
          p : filterPrime [x | x <- xs, x `mod` p /= 0]
  • Haskell is beautiful and concise. Plus, haskell notation is designed to be similar to usual mathematical notation.

Here is an implementation of the Bisection Algorithm in Haskell:

bisection :: (Float -> Float) -> Float -> Float -> Float -> Float
bisection f a b eps
    | (abs $ f mid) < eps    = mid
    | f mid > 0              = bisection f a mid eps
    | f mid < 0              = bisection f mid b eps
        mid = (a+b)/2

And for the technically inclined,

  • Haskell is statically typed. The type of every expression is known at compile time. This makes it harder for the programmer to make errors.
  • Haskell has extensive support for concurrency. This is especially simpler because of the way haskell deals with side effects.
  • There are a large number of haskell libraries with support for purposes ranging from networking, graphics, parsers and more.

Are there Computer Science problems on Brilliant which have been solved by Haskell?


Also, this note on enumerating Integer Partitions

Can you give me a short feel of what haskell is like?

Check out this 10 minute online tutorial.

For larger snippets of code, you could use ideone

What are the prerequisites for the course?

None; but installing the haskell interpreter helps. Alternately, you could just always use ideone

Where can I get more details about the course?

The NPTEL Course Page

Note by Agnishom Chattopadhyay
2 weeks, 2 days ago

No vote yet
1 vote


There are no comments in this discussion.


Problem Loading...

Note Loading...

Set Loading...