Authors: Claire Anderson and Madeline Francis
Github Repository: https://github.com/cmaija/Haskellconnect4
What is the problem?
Implement the Connect Four game (https://en.wikipedia.org/wiki/Connect_Four).
What is the something extra?
We implemented a really simple AI to play with. The game has this 1 player option but can be played with 2 humans as well.
What did we learn from doing this?
We are better able to understand the paradigm of functional programming after using it in this project. We articulate it as triggering an original function which in our program triggers a chain of other functions, using the result of the preceding and the input to the following. Since in functional programming state is not saved anywhere in variables, we had to use the IO() type to temporarily pause this chain of function calling to use intermediate results and wait for user input. This kind of gives the illusion of state being saved when playing the connect 4 game but really its just a pause in the chaining of function calls.
When trying to iterate over rows and columns of our game Board matrix, at first it was difficult to not think in terms of imperative loops. We attempted to look for ways to implement imperative loops and through research learned what exactly declarative programming is. Roughly... "If I'm imperative, I'm telling you how it is. If I'm declarative, I'm telling you what it is." - top answer @ https://www.quora.com/Why-doesnt-Haskell-have-loops-e-g-for-or-while .. This quote snapped us back into using recursion in situations where we needed to loop.
We became a lot more aware of the specific types of all of our functions and inputs as time went on given the constant compiler errors. We also grew comfortable creating our own typeclasses, accessing their fields etc. It was also necessary to understand instances in context of displaying our Board data type with Show.