So, I am very good at algebraic types and class types, but I am interested in its design and development.
What is the current consensus, if any, in classrooms? Are they evil? Are they comfortable? Should they be used and when?
Here is my case study. I am writing a game in the style of RTS, and I have different "units" (tank, reconnaissance, etc.). Let's say I want to get the maximum amount of health for each unit. My two thoughts on how to determine their types are as follows:
Various ADT constructors:
data Unit = Scout ... | Tank ... maxHealth :: Unit -> Int maxHealth Scout = 10 maxHealth Tank = 20
Typeclass for Unit, each view is an instance
class Unit a where maxHealth :: a -> Int instance Unit Scout where maxHealth scout = 10 instance Unit Tank where maxHealth tank = 20
Obviously, the final product will have more fields and functions. (For example, each unit will have a different position, etc., Therefore, not all functions will be constant).
The trick is that some units may have some functions, but not others. For example, each unit will have a getPosition function, but a tank may have a getArmour function, which does not make sense to a scout without armor.
What is the “generally accepted” way to write this if I want other Haskellers to understand and follow my code?