Skip to content

Commit c6ec581

Browse files
aestevebishabosha
andauthored
explaining the difference between OO polymorphism and ad-hoc polymorphism
Co-Authored-By: Jamie Thompson <[email protected]>
1 parent 6b6cd39 commit c6ec581

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,6 @@ given readerMonad[Ctx] as Monad[[X] =>> Ctx => X] {
267267

268268
The definition of a _typeclass_ is expressed via a parameterised type with abstract members, such as a `trait`.
269269
The main difference between object oriented polymorphism, and ad-hoc polymorphism with _typeclasses_, is how the definition of the _typeclass_ is implemented, in relation to the type it acts upon.
270-
In the case of a _typeclass_ the trait's implementations are expressed through `given ... as` type definitions, and not through classes that `extends` the trait linearly.
270+
In the case of a _typeclass_, its implementation for a concrete type is expressed through a `given ... as` term definition, which is supplied as an implicit argument alongside the value it acts upon. With object oriented polymorphism, the implementation is mixed into the parents of a class, and only a single term is required to perform a polymorphic operation.
271271

272272
In addition to these given instances, other constructs like extension methods, context bounds and type lambdas allow a concise and natural expression of _typeclasses_.

0 commit comments

Comments
 (0)