Hackwell in Haskell: a Haskell hackathon in StackBuilders
Today have taken place in the StackBuilders offices in Quito what seems to be the first Hackathon using a funcional language, in Ecuador. For this ocasion, we’ve been using Haskell.
Haskell is a functional programming language created in 1990 that takes its name from Haskell Curry, an american mathematician in which works about logics are partially based the current functional programming languages. Haskell is a strongly typed language, although it differs from other functional languages as Clojure in not forcing the data structures inmutability.
During the day, the problem proposed was solving the snail kata in Haskell. The snail kata consist in, given a squared matrix, return an array with all the matrix elements sorted as is shown in the following diagram:
So, for the next matrix:
array = [[1,2,3],
the expected result of applying snail should be:
snail(array) #=> [1,2,3,6,9,8,7,4,5]
Speaking about the hackathon itself, I must say that it was really fun, that I’ve learned a lot, and that I’m very satisfied with the solution that my pair and me have developed, taking into account that it has been our first code in Haskell. There have been beer, pizza, and several funny moments 🙂
About our solution, we’ve developed a first algorithm that:
- Extracts the upper row.
- Extracts the right column without the first element (which is already included in the upper row).
- Concats the above with the result of calling again the function with the lower left submatrix, rotated 180 degrees.
After that, we have refined it to the following algorithm:
- Extract all the matrix perimeter, concatenated in the correct order.
- Concat the above with the result of calling again the function with the inner matrix (without the perimeter).
The solution is available in my Github account.
As pending tasks, I still need to learn how to test in Haskell. It has been quite an experience to program without tests after so much time applying TDD 100% of my time, and it has been like driving a car without safety belt. Also, I’ve confirmed again how much time is wasted when you lack automated tests.