Skip to content

Commit 6fac698

Browse files
committed
Adjust the title levels in context-bounds.md
1 parent 5cdfd31 commit 6fac698

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

docs/docs/reference/contextual/context-bounds.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,31 @@ layout: doc-page
33
title: "Context Bounds"
44
---
55

6-
## Context Bounds
7-
86
A context bound is a shorthand for expressing the common pattern of a context parameter that depends on a type parameter. Using a context bound, the `maximum` function of the last section can be written like this:
7+
98
```scala
109
def maximum[T: Ord](xs: List[T]): T = xs.reduceLeft(max)
1110
```
11+
1212
A bound like `: Ord` on a type parameter `T` of a method or class indicates a context parameter `with Ord[T]`. The context parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g.,
13+
1314
```scala
1415
def f[T: C1 : C2, U: C3](x: T)(using y: U, z: V): R
1516
```
17+
1618
would expand to
19+
1720
```scala
1821
def f[T, U](x: T)(using y: U, z: V)(using C1[T], C2[T], C3[U]): R
1922
```
23+
2024
Context bounds can be combined with subtype bounds. If both are present, subtype bounds come first, e.g.
25+
2126
```scala
2227
def g[T <: B : C](x: T): R = ...
2328
```
2429

25-
### Migration
30+
## Migration
2631

2732
To ease migration, context bounds in Dotty map in Scala 3.0 to old-style implicit parameters
2833
for which arguments can be passed either with a `(using ...)` clause or with a normal application. From Scala 3.1 on, they will map to context parameters instead, as is described above.
@@ -32,7 +37,7 @@ context parameter stemming from a context bound with a normal argument will give
3237
warning. The warning indicates that a `(using ...)` clause is needed instead. The rewrite can be
3338
done automatically under `-rewrite`.
3439

35-
### Syntax
40+
## Syntax
3641

3742
```
3843
TypeParamBounds ::= [SubtypeBounds] {ContextBound}

0 commit comments

Comments
 (0)