Why is a "type class" called "type class"?
When diving deeper into Scala I hit the term type class. It had been confusing because a class is a type and a type could be a class in S开发者_如何学Ccala and "type" and "class" are in itself abstract terms.
After reading some examples I got a feeling what a type class could be, but maybe there is an easier approach to get a mental hook (picture, concept) to what a type class is by explaining why it had been named like that.
In Haskell there are no classes in Java/Scala sense, so this term was free to be used (in the sense "class of types", as Johannes Weiß says).
It isn't used in official Scala documentation, but people coming from Haskell found they could emulate Haskell type classes in Scala and reused the name.
Because it classes (together) types "having" a common set operations defined by the type class?
It feels very natural to me.
精彩评论