开发者

Why is a "type class" called "type class"?

开发者 https://www.devze.com 2023-04-04 05:40 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消