Snake-game
Authors: Saad and Aymen
What is the problem?
We are choosing to assess the feasibility of implementing the snake game in Haskell. We plan to have all the basic functionality of Snake. In specific:
- The snake should grow as it eats food
- The game will end when the snake eats itself or hits a boundary
- The snake should move according to user input
What is the something extra?
We plan for there to be a UI component to this project which we believe will be special in the context of a purely functional language. There exist many object-oriented UI libraries or functional style UI libraries in object-oriented languages, but we wish to explore what exists and what it takes to build one in Haskell with or without a library.
What did we learn from doing this?
(This should be written after you have done the work.)
- What is the bottom-line?
We learned how to create projects in Haskell from scratch, including but not limited to setting up the work environment, handling packages, adhering to Haskell best practices when organizing code, and the importance of Worlds when trying to work with state.
- Is functional programming suitable for (part-of) the task?
Yes it is suitable for the backend logic of the game. Our entire game depends on the output of one function being passed into other functions to work smoothly. Since Haskell has such a strong statically typed interface, we were able to craft the exact flow of functions input/output at compile time. On a more low level, it is very easy to manage food consumption of the snake. While in a more OO language we would've needed to create some complex data structure to efficiently traverse the entire snake and push/pop the first/last elements of the list, in Haskell we can easily take advantage of the append (:) operator to manage all this for us in one line.
Additionally, we leveraged Haskell's functional style to construct our UI in terms of functions that consume one state of our Game and produce a new updated state of the Game. This simplified the development process and led to less bugs overall.
- Make sure you include the evidence for your claims.
Where? In the demo?