Skip to content

Commit 610bd13

Browse files
committed
Edits to Functor intro
- Convert to Typst - Assorted wordsmithing
1 parent 83f747a commit 610bd13

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/pages/functors/index.typ

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ is more general than this.
8484
Let's investigate the behaviour of some other functors
8585
that apply the pattern in different ways.
8686

87-
*Futures*
87+
88+
=== Futures
8889

8990
`Future` is a functor that
9091
sequences asynchronous computations by queueing them
@@ -129,12 +130,10 @@ val future: Future[String] =
129130
Await.result(future, 1.second)
130131
```
131132

132-
#info[
133-
*Futures and Referential Transparency*
134-
133+
#info(title: "Futures and Referential Transparency")[
135134
Note that Scala's `Futures` aren't a great example
136135
of pure functional programming
137-
because they aren't _referentially transparent_.
136+
because they aren't *referentially transparent*.
138137
`Future` always computes and caches a result
139138
and there's no way for us to tweak this behaviour.
140139
This means we can get unpredictable results
@@ -197,7 +196,8 @@ If `Future` isn't referentially transparent,
197196
perhaps we should look at another similar data-type that is.
198197
You should recognise this one...
199198

200-
*Functions (?!)*
199+
200+
=== Functions (?!)
201201

202202
It turns out that single argument functions are also functors.
203203
To see this we have to tweak the types a little.
@@ -266,9 +266,7 @@ val func =
266266
func(123)
267267
```
268268

269-
#warning[
270-
*Partial Unification*
271-
269+
#warning(title: "Partial Unification")[
272270
For the above examples to work,
273271
in versions of Scala before 2.13,
274272
we need to add the following compiler option to `build.sbt`:
@@ -323,11 +321,9 @@ trait Functor[F[_]] {
323321

324322
If you haven't seen syntax like `F[_]` before,
325323
it's time to take a brief detour to discuss
326-
*type constructors_ and _higher kinded types*.
327-
328-
#warning[
329-
*Functor Laws*
324+
*type constructors* and *higher kinded types*.
330325

326+
#warning(title: "Functor Laws")[
331327
Functors guarantee the same semantics
332328
whether we sequence many small operations one by one,
333329
or combine them into a larger function before `mapping`.
@@ -348,17 +344,17 @@ fa.map(g(f(_))) == fa.map(f).map(g)
348344
```
349345
]
350346

351-
== Aside: Higher Kinds and Type Constructors
352347

348+
== Higher Kinds and Type Constructors
353349

354350
Kinds are like types for types.
355351
They describe the number of "holes" in a type.
356352
We distinguish between regular types that have no holes
357-
and "type constructors" that have
353+
and *type constructors* that have
358354
holes we can fill to produce types.
359355

360356
For example, `List` is a type constructor with one hole.
361-
We fill that hole by specifying a parameter to produce
357+
We fill that hole with a type to produce
362358
a regular type like `List[Int]` or `List[A]`.
363359
The trick is not to confuse type constructors with generic types.
364360
`List` is a type constructor, `List[A]` is a type:

0 commit comments

Comments
 (0)