Skip to content

EvanMisshula/haskell-katas

Repository files navigation

Haskell Katas

Atilla’s Intro

As I try to learn Haskell, I realized reading and following examples is not enough, I needed short examples I could practice daily. I found Attila Dokomos’ Haskell Katas.

The examples in this repo are mostly from the book [Learn You a Haskell for Great Good!](http://learnyouahaskell.com/), although Attilla Dokomos started incorporating other examples as well.

My contribution

My contribution, such as it is, is that I took this repository and got it to run with NixOS. Nix is a system for manging builds and configuration. Although complicated many on the cutting edge of Haskell Development find it indispensible particularly for building composable User Interface elements as Functional Reactive Programming. I also added support for Emacs math and its unicode symbols.

From a pedogical viewpoint, I think it is important to tie programming in Haskell to the composition of functions. Using the same symbols helps concretize what can be a very abstract analogy.

Katas and eductaional philosphy

The idea of a ”code-kata” was introduced by Dave Thomas in 1999. The idea was that mastery required the practice of small increasingly difficult exercises. The name was chosen to emphasize the analogy of learning an Asian Martial art. The idea is to prioritize active but supported learning with small steps forward.

Great Programmers, great mathematicians are not born but made with a lot of hard work.

Install Nix and complete the nix-haskell tutorial

Follow Gabriel Garcia’s Haskell and Nix in production. This will install nix and the only tools you should have in your environment.

Using this repository

I have a write up and a screencast. None of this will work if you have not gone through and the tutorial in the section above. The video should give you an idea of what this is supposed to look like and if you have gone off the path. The write up emphasizes subtle things that you may need to read more than once to get working.

Finding the screencast

The video is available at: https://youtu.be/OBJV2nwhEAo

A small write up

There are two branches, master and solutions. First read a topic in [Learn You a Haskell for Great Good!](http://learnyouahaskell.com/). Use emacs to open a file of the numbered exercises. They are in the test directory. Stay in the master branch.

Let’s run the tests for code we have not written:

  1. We create a nix-shell that has all of the libraries installed for this project. The shell.nix takes care of this for us. Simply type in this directory:
nix-shell

Now we have ghci in our path. This is the part of the Haskell Compiler that runs an interpreter.

 Prelude> :load test/EX01_ListsExtractingSpec
 EX01_ListsExtractingSpec> main

Extracting Portion of List
  finds the first element in a list
    # PENDING: No reason given
  finds the tail part of a list
    # PENDING: No reason given
  finds the last element in a list
    # PENDING: No reason given
  extracts the elements except the last one from a list
    # PENDING: No reason given
  takes elements from a list
    # PENDING: No reason given
  can drop elements from a list
    # PENDING: No reason given
  can split a collection
    # PENDING: No reason given
  can take with a while
    # PENDING: No reason given
  can drop while
    # PENDING: No reason given

Finished in 0.0710 seconds
9 examples, 0 failures, 9 pending

You should substitute the word pending with the solution.

it "finds the first element in a list" $
  pending

with:

it "finds the first element in a list" $
  head [1, 2, 3, 4, 5] `shouldBe` 1

Running the tests after this change should yield something close to:

 Prelude> :load test/EX01_ListsExtractingSpec
 EX01_ListsExtractingSpec> main


Extracting Portion of List
  finds the first element in a list
  finds the tail part of a list
    # PENDING: No reason given
  finds the last element in a list
    # PENDING: No reason given
  extracts the elements except the last one from a list
    # PENDING: No reason given
  takes elements from a list
    # PENDING: No reason given
  can drop elements from a list
    # PENDING: No reason given
  can split a collection
    # PENDING: No reason given
  can take with a while
    # PENDING: No reason given
  can drop while
    # PENDING: No reason given

Finished in 0.0131 seconds
9 examples, 0 failures, 8 pending

We have no failures and only 8 rather than 9 pending. Good luck!