Homework to practice different ways of branching in Haskell and modularization
Open src/Lib.hs and implement all the TODOs there. You can also check the specification in test/Spec.hs and run the tests with stack test.
To complete you will need to work also with src/Data/MyString/Examples.hs and src/Data/DummyList/Examples.hs, but you are not allowed to change those nor data types in src/Lib.hs and it is also forbidden to add new dependencies.
czechSalutationshould return salutation (in nominative, 1st case = "1. pád") in the Czech language for given person (gender, age, marital status and academic titles must be used appropriately). For details read the comment in code and check test specification, you can also read (1), (2), and (3) if interested (Czech only). Do not edit prepared data types, just implement the function.intervalContainsshould tell for given number if is in interval or not. Do not edit prepared data type, just implement the function.shapeCircumferenceandshapeAreashould return circumference and area of given shape (can be Circle, Square, Rectangle, or Triangle), we can assume only valid shapes. Do not edit prepared data type, just implement the function.geometricSequenceshould return for givena(first parameter) andr(second parameter) a geometric sequence as endless list.fibonacciNumbersshould return an endless list of Fibonacci numbers. Try to find a solution on your own and enjoy laziness with Haskell - it is so easy...matrixMultiplicationreturns a product of two matricesxandy(matrix multiplication, check the size). You must use list comprehension!dummyListExample1,stringExample2,stringExample3should be assigned with values fromData.DummyList.Examples(example1) andData.MyString.Examples(example2andexample3). It is not allowed to copy or "implement" them, working import must be used.
Hints & general requirements:
- Being DRY is essential, do not repeat code (for example, in inversed comparison of intervals). However, do not forget AHA principle as well.
- Local names (via
whereorlet-in) in functions should be introduced to make the code more readable. Creating helper functions in module scope is awful. - Avoid using
if-then-elsewith patterns and guards (and/or combination of those two) if possible and better for readability. - Look up functions that can help you (
Prelude,Data.List) with general tasks like finding a maximum in list, convertingIntegersto generic numbers, or getting unique values from a list. Do not re-invent the wheel! - You must understand your code completely!
- Draw the problem and try to split it
- Try to think in functions (what are inputs and output), try to decompose to simpler functions if it gets too complex
- Start with simple cases and build more complex (bottom-up)
- If you are really stuck, open issue or as in merge request
- Try to start with simpler tasks: 2, 3, 4, 5, 7; esp. 2 and 3 will help you with grasping pattern-matching and branching needed in 1
- Homeworks are designed to learn, do not hesitate to consult with teacher!
- In case of uncertainty, check the dummy homework to recall what is the homework workflow for this course.
- If you encounter some trouble, create an issue in your repository.
- In case you find a bug or have an idea how to improve assignment project, create an issue or PR in this repository.
This project is licensed under the MIT License - see the LICENSE file for more details.