Homework to practice work with typeclasses
Homework to practice advanced work with typeclasses
area
and circumference
for various shapes in the third homework. Now you will do something similar, but using typeclasses in Data.Shapes
!Validable
for each shape type with function valid
that says if given shape is valid (its attributes are acceptable, i.e., not negative, forming a triangle).Shape2D
typeclass which is a subclass of Validable
, define area
and circumference
(remove dummy ones). During the design consider using valid
- for invalid shape, both functions should return zero.Shape2D
for each shape type.SortedList
to be an instance of Semigroup
, Monoid
, Functor
, Applicative
, Monad
. After applying (<>)
the resulting list must be sorted. Sadly, Functor
, Applicative
, and Monad
won’t allow you to use Ord
constaint so the result won’t be sorted. Implement some sort function if you want to… It is forbidden to just delegate to list and use fromList
and toList
.RomanNumeral
(from Data.RomanNumeral
)! It is a representation of an integer as Roman numeral, for example, 125
is "CXXV"
.integral2RomanNumeral
and romanNumeral2Integral
(related with pack
and unpack
). There is something already prepared in Data.RomanNumeral.Helpers
. Take a look and feel free to edit as you need.pack
and unpack
working, it will be very easy to make instances of Bounded
, Eq
, Ord
, Num
, Enum
, and Integral
(you might need some more due to dependencies) for the RomanNumeral
.Hints & general requirements:
Data.RomanNumeral
- use only those defined in Data.RomanNumeral.Helpers
or enhance it.where
or let-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.This project is licensed under the MIT License - see the LICENSE
file for more details.