Happenings of the First Hands On Haskell Workshop
After spending the initial (slightly chaotic) half an hour helping everyone get set up with their haskell tools:
A docker image from a tar hosted on the LAN
Downloading haskell-platform for their env, and then running
cabal update && cabal install scotty.
Everyone downloaded hoh-code tarball that was hosted locally for them to get started with exercises. Thanks to AJ for coming up with a great set of simple problems.
We proceeded in the following way with Haskell (by Tanmai):
Thinking in terms of input and output, and with pure functions only
Expressing input-output as type signatures
Experimenting with type signatures on ghci with Prelude functions
Applying functions from prelude. Like
(+) 1 2and
Starting messing around with src/FunctionsExpr.hs. Type signatures of a few simple functions like add, subtract were written, and their implementation was simply set to
The exercise was to implement the functions, and then test them out with ghci
We went over basic syntax, expressions, if-else branching, basic recursion
The complexity was slightly increased with src/Addendum.hs which contained common functions on lists
More examples with pattern matching, and recursion
Quintessential quick sort example! Showing the ‘top-down’ thinking at work, the conciseness in implementation
Introduction to higher order functions, partial functions, and basic examples showing how functions are just values
After the basic exercises and a little coffee and tea break, we dove into a few more advanced examples of Haskell
We had a session on discussing lazy evaluation, and how purity and lazy evaluation work so well together (by Vamshi)
Trying out examples like
take n [1..]
Discussing composition and laziness with how things like
quadrupleMe = doubleMe . doubleMeand how
take n (quadrupleMe [1..])worked so naturally
We then proceeded to another more advanced concept, that offers something very powerful to programmers:
Equational reasoning and its impact on refactoring and evolving codebases. Eg: take one bit out, optimize it etc.
Understanding how purity and the type system let us have beautiful things like Quickcheck
Testing with invariants: x == reverse (reverse x)
Testing with reference implementations. Brandon went over a great example of how he tested his streaming solution of the twitter water problem with a elegant 3 line solution by Philip Nilsson. The solution worked for some common inputs, but failed on inputs of a particular pattern. Testing with quickcheck against the elegant reference implementation helped him quickly find the bug. And the automatic test-case shrinking just nailed it.
The session was very interactive, and the great (air-conditioned!) venue was organized thanks to Shahidh and the IITM WebOps guys. A very interested and diverse audience kept the full 4 hours very occupied! We also got to meet some interesting folks from in and around Chennai regularly using Haskell.
We should have the next workshop/meetup soon!