Skip to content

Commit df15a24

Browse files
author
Arnaud ESTEVE
committed
Trying to add an easy-to-grasp definition of type classes
1 parent f2d7a6d commit df15a24

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

docs/docs/reference/contextual/typeclasses-new.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ layout: doc-page
33
title: "Implementing Typeclasses"
44
---
55

6-
In Scala 3, _typeclasses_ are just traits whose implementation are defined by given instances.
7-
Here are some examples of standard typeclasses:
6+
A _typeclass_ is an abstract, parameterized type that lets you add new behavior to any closed data type without using sub-typing. This can be useful in multiple use-cases, for example:
7+
* expressing how a type you don't own (from the standard or 3rd-party library) conforms to such behavior
8+
* expressing such a behavior for multiple types without involving sub-typing relationships (one `extends` another) between those types (see: [ad hoc polymorphism](https://en.wikipedia.org/wiki/Ad_hoc_polymorphism) for instance)
9+
10+
Therefore in Scala 3, _typeclasses_ are just _traits_ with one or more parameters whose implementations are not defined through the `extends` keyword, but by **given instances**.
11+
Here are some examples of usual typeclasses:
812

913
### Semigroups and monoids:
1014

0 commit comments

Comments
 (0)