Skip to content

Commit cf89591

Browse files
committed
Add Higher-Kinded Types section to Scala Tour
1 parent e972ef4 commit cf89591

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
---
2-
layout: multipage-overview
3-
title: Advanced Type Features
4-
partof: scaladoc
5-
overview-name: Scaladoc
6-
num: 4
7-
permalink: /overviews/scaladoc/advanced-type-features.html
2+
layout: tour
3+
title: Higher-Kinded Types
4+
permalink: /tour/higher-kinded-types.html
85
---
96

10-
# Advanced Type Features in Scala
7+
# Higher-Kinded Types
118

12-
This section introduces some advanced type system features in Scala, including **Higher-Kinded Types (HKT)**, type bounds, and type projections.
9+
This section introduces Higher-Kinded Types (HKT), an advanced type system feature in Scala, along with related concepts like type bounds and type projections.
1310

14-
## Higher-Kinded Types
11+
## What are Higher-Kinded Types?
1512

1613
Higher-Kinded Types allow abstracting over type constructors. For example:
1714

@@ -33,15 +30,16 @@ val optionFunctor = new Functor[Option] {
3330
val result = optionFunctor.map(Some(2))(_ * 2) // Some(4)
3431
```
3532

36-
## Type Bounds
33+
## Type Bounds and Typeclasses
3734

38-
Scala supports upper and lower bounds:
35+
Scala supports upper and lower bounds and commonly uses typeclasses for comparison:
3936

4037
```scala
41-
def max[T <: Ordered[T]](x: T, y: T): T = if (x > y) x else y
38+
def max[T](x: T, y: T)(implicit ord: Ordering[T]): T =
39+
if (ord.gt(x, y)) x else y
4240
```
4341

44-
Here `T <: Ordered[T]` means `T` must implement `Ordered`.
42+
Here `Ordering[T]` provides comparison logic for type `T` using a typeclass pattern.
4543

4644
## Type Projections
4745

0 commit comments

Comments
 (0)