Similar types may be related using type classes. Watch Jeremy Singer introduce some existing type classes in Haskell.
Share this step
Inevitably, we have glossed over some of the more complex parts of Haskell while we have been introducing the language. Now it’s time to explore one of the ideas we have bumped into on several occasions already — type classes.
What’s the type of 42? Either type 42 into the online interpreter or enter
:t 42
in GHCi. Either way, you should get back Num a => a — whereas you might have thought the answer should be Int. The Num is a type class, which specifies a family of types including integer and floating-point types.
We also anticipated type classes when we used the deriving Show clause to print out our custom data types. Now it’s time to explain type classes in more detail. Please watch the video and think about the concepts. Do type classes remind you of features in other languages? Leave your thoughts in the comments section.