Homework to practice advanced work with typeclasses
- You've already done some implementation of
areaandcircumferencefor various shapes in the third homework. Now you will do something similar, but using typeclasses inData.Shapes!- First, implement instances of
Validablefor each shape type with functionvalidthat says if given shape is valid (its attributes are acceptable, i.e., not negative, forming a triangle). - Then, design on your own the
Shape2Dtypeclass which is a subclass ofValidable, defineareaandcircumference(remove dummy ones). During the design consider usingvalid- for invalid shape, both functions should return zero. - Finally, implement instances of
Shape2Dfor each shape type.
- First, implement instances of
- Data.SortedList = implement all necessary functions to make data type
SortedListto be an instance ofSemigroup,Monoid,Functor,Applicative,Monad. After applying(<>)the resulting list must be sorted. Sadly,Functor,Applicative, andMonadwon't allow you to useOrdconstaint so the result won't be sorted. Implement some sort function if you want to... It is forbidden to just delegate to list and usefromListandtoList. - The final (and also the most interesting) task is to implement functions and instances for next data type to represent integers - the
RomanNumeral(fromData.RomanNumeral)! It is a representation of an integer as Roman numeral, for example,125is"CXXV".- The biggest challenge is to implement functions
integral2RomanNumeralandromanNumeral2Integral(related withpackandunpack). There is something already prepared inData.RomanNumeral.Helpers. Take a look and feel free to edit as you need. - After having
packandunpackworking, it will be very easy to make instances ofBounded,Eq,Ord,Num,Enum, andIntegral(you might need some more due to dependencies) for theRomanNumeral.
- The biggest challenge is to implement functions
Hints & general requirements:
- You should not hardcode any string or character in
Data.RomanNumeral- use only those defined inData.RomanNumeral.Helpersor enhance it. - Being DRY is essential, do not repeat code. Name expressions to reuse then, introduce helper functions.
- Local names (via
whereorlet-in) in functions should be introduced to make the code more readable. Creating very simple helper functions in module scope is not nice. If you need some complicated functions create separate "private" module. - Make your code as clean as possible. Prefer pattern matching and syntactic sugar everywhere it is reasonable.
- You must understand your code completely!
- 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.
- It might happen that tests are not 100% bulletproof, but your solution should be correct. If you want, propose tests enhancements.
This project is licensed under the MIT License - see the LICENSE file for more details.