Skip to content

Commit 052c2cf

Browse files
Fix code blocks in the documentation
A previous commit disabled indentation-based code blocks because it's incompatible with liquid template inclusion. This commit replaces all indented code blocks by backticks-surrounded code blocks. It also adds missing language declarations (for syntax highlighting) and removes some annoying extra indentation.
1 parent c801013 commit 052c2cf

File tree

61 files changed

+1320
-1313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1320
-1313
lines changed

docs/blog/_posts/2016-02-03-essence-of-scala.md

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@ has been machine-checked for correctness.
2424
A calculus is a kind of mini-language that is small enough to be
2525
studied formally. Translated to Scala notation, the language covered
2626
by DOT is described by the following abstract grammar:
27-
28-
Value v = (x: T) => t Function
29-
new { x: T => ds } Object
30-
31-
Definition d = def a = t Method definition
32-
type A = T Type
33-
34-
Term t = v Value
35-
x Variable
36-
t1(t2) Application
37-
t.a Selection
38-
{ val x = t1; t2 } Local definition
39-
40-
Type T = Any Top type
41-
Nothing Bottom type
42-
x.A Selection
43-
(x: T1) => T2 Function
44-
{ def a: T } Method declaration
45-
{ type T >: T1 <: T2 } Type declaration
46-
T1 & T2 Intersection
47-
{ x => T } Recursion
48-
27+
```
28+
Value v = (x: T) => t Function
29+
new { x: T => ds } Object
30+
31+
Definition d = def a = t Method definition
32+
type A = T Type
33+
34+
Term t = v Value
35+
x Variable
36+
t1(t2) Application
37+
t.a Selection
38+
{ val x = t1; t2 } Local definition
39+
40+
Type T = Any Top type
41+
Nothing Bottom type
42+
x.A Selection
43+
(x: T1) => T2 Function
44+
{ def a: T } Method declaration
45+
{ type T >: T1 <: T2 } Type declaration
46+
T1 & T2 Intersection
47+
{ x => T } Recursion
48+
```
4949
The grammar uses several kinds of names:
50-
51-
x for (immutable) variables
52-
a for (parameterless) methods
53-
A for types
54-
50+
```
51+
x for (immutable) variables
52+
a for (parameterless) methods
53+
A for types
54+
```
5555
The full calculus adds to this syntax formal _typing rules_ that
5656
assign types `T` to terms `t` and formal _evaluation rules_ that
5757
describe how a program is evaluated. The following _type soundness_
@@ -67,12 +67,12 @@ because it uncovered some technical challenges that had not been
6767
studied in depth before. In DOT - as well as in many programming languages -
6868
you can have conflicting definitions. For instance you might have an abstract
6969
type declaration in a base class with two conflicting aliases in subclasses:
70-
71-
trait Base { type A }
72-
trait Sub1 extends Base { type A = String }
73-
trait Sub2 extends Base { type A = Int }
74-
trait Bad extends Sub1 with Sub2
75-
70+
```scala
71+
trait Base { type A }
72+
trait Sub1 extends Base { type A = String }
73+
trait Sub2 extends Base { type A = Int }
74+
trait Bad extends Sub1 with Sub2
75+
```
7676
Now, if you combine `Sub1` and `Sub2` in trait `Bad` you get a conflict,
7777
since the type `A` is supposed to be equal to both `String` and `Int`. If you do
7878
not detect the conflict and assume the equalities at face value you
@@ -108,10 +108,10 @@ project are important.
108108
Nominal typing means that a type is distinguished from others
109109
simply by having a different name.
110110
For instance, given two trait definitions
111-
112-
trait A extends AnyRef { def f: Int }
113-
trait B extends AnyRef { def f: Int }
114-
111+
```scala
112+
trait A extends AnyRef { def f: Int }
113+
trait B extends AnyRef { def f: Int }
114+
```
115115
we consider `A` and `B` to be different types, even though both
116116
traits have the same parents and both define the same members.
117117
The opposite of
@@ -143,4 +143,3 @@ project are important.
143143
either to increase our confidence that they are indeed sound, or
144144
to show that they are unsound. In my next blog I will
145145
present some of the issues we have discovered through that exercise.
146-

docs/blog/_posts/2016-02-17-scaling-dot-soundness.md

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ guidelines on how to design a sound type system for full Scala.
1717
As was argued in the previous blog post, the danger a path-dependent type
1818
system like Scala's faces is inconsistent bounds or aliases. For
1919
instance, you might have a type alias
20-
21-
type T = String
22-
20+
```scala
21+
type T = String
22+
```
2323
in scope in some part of the program, but in another part the same
2424
type member `T` is known as
25-
26-
type T = Int
27-
25+
```scala
26+
type T = Int
27+
```
2828
If you connect the two parts, you end up allowing assigning a `String`
2929
to an `Int` and vice versa, which is unsound - it will crash at
3030
runtime with a `ClassCastException`. The problem is that there
@@ -51,17 +51,17 @@ a type selection might _not_ be a value that's constructed with a
5151
categories:
5252

5353
1. The prefix value might be lazy, and never instantiated to anything, as in:
54-
55-
lazy val p: S = p
56-
... p.T ...
57-
54+
```scala
55+
lazy val p: S = p
56+
... p.T ...
57+
```
5858
Note that trying to access the lazy value `p` would result in an infinite loop. But using `p` in a type does not force its evaluation, so we might never evaluate `p`. Since `p` is not initialized with a `new`, bad bounds for `T` would go undetected.
5959

6060
2. The prefix value might be initialized to `null`, as in
61-
62-
val p: S = null
63-
... p.T ...
64-
61+
```scala
62+
val p: S = null
63+
... p.T ...
64+
```
6565
The problem here is similar to the first one. `p` is not initialized
6666
with a `new` so we know nothing about the bounds of `T`.
6767

@@ -73,16 +73,20 @@ at the discussion for issues [#50](https://github.com/lampepfl/dotty/issues/50)
7373
and [#1050](https://github.com/lampepfl/dotty/issues/1050) in the
7474
[Dotty](https://github.com/lampepfl/dotty/issues/1050) repository
7575
on GitHub. All issues work fundamentally in the same way: Construct a type `S`
76-
which has a type member `T` with bad bounds, say
76+
which has a type member `T` with bad bounds, say:
7777

78-
Any <: T <: Nothing
78+
```scala
79+
Any <: T <: Nothing
80+
```
7981

8082
Then, use the left subtyping to turn an expression of type `Any` into
8183
an expression of type `T` and use the right subtyping to turn that
8284
expression into an expression of type `Nothing`:
8385

84-
def f(x: Any): p.T = x
85-
def g(x: p.T): Nothing = x
86+
```scala
87+
def f(x: Any): p.T = x
88+
def g(x: p.T): Nothing = x
89+
```
8690

8791
Taken together, `g(f(x))` will convert every expression into an
8892
expression of type `Nothing`. Since `Nothing` is a subtype of every
@@ -150,10 +154,3 @@ should make sure not to back-slide. And if the experience of the past
150154
10 years has taught us one thing, it is that the meta theory of type
151155
systems has many more surprises in store than one might think. That's
152156
why mechanical proofs are essential.
153-
154-
155-
156-
157-
158-
159-

docs/blog/_posts/2016-05-05-multiversal-equality.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ How can `==` be fixed? It looks much harder to do this than adding an alternate
2424

2525
The current status in Scala is that the compiler will give warnings for _some_ comparisons that are always `false`. But the coverage is weak. For instance this will give a warning:
2626

27-
```
27+
```scala
2828
scala> 1 == "abc"
2929
<console>:12: warning: comparing values of types Int and String using `==' will always yield false
3030
```
3131

3232
But this will not:
3333

34-
```
34+
```scala
3535
scala> "abc" == 1
3636
res2: Boolean = false
3737
```
@@ -45,29 +45,29 @@ I believe to do better, we need to enlist the cooperation of developers. Ultimat
4545

4646
The best known way to characterize such relationships is with type classes. Implicit values of a trait `Eq[T, U]` can capture the property that values of type `T` can be compared to values of type `U`. Here's the definition of `Eq`
4747

48-
```
48+
```scala
4949
package scala
5050

5151
trait Eq[-T, -U]
5252
```
5353

5454
That is, `Eq` is a pure marker trait with two type parameters and without any members. Developers can define equality classes by giving implicit `Eq` instances. Here is a simple one:
5555

56-
```
56+
```scala
5757
implicit def eqString: Eq[String, String] = Eq
5858
```
5959

6060
This states that strings can be only compared to strings, not to values of other types. Here's a more complicated `Eq` instance:
6161

62-
```
62+
```scala
6363
implicit def eqOption[T, U](implicit _eq: Eq[T, U]): Eq[Option[T], Option[U]] = Eq
6464
```
6565

6666
This states that `Option` values can be compared if their elements can be compared.
6767

6868
It's foreseen that such `Eq` instances can be generated automatically. If we add an annotation `@equalityClass` to `Option` like this
6969

70-
```
70+
```scala
7171
@equalityClass class Option[+T] { ... }
7272
```
7373

0 commit comments

Comments
 (0)