You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/adt/conclusions.typ
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
#import"../stdlib.typ": info, warning, solution
1
+
#import"../stdlib.typ": href
2
2
== Conclusions
3
3
4
4
@@ -25,18 +25,18 @@ Below are some references that you might find useful if you want to dig in furth
25
25
26
26
Algebraic data types are standard in introductory material on functional programming.
27
27
Structural recursion is certainly extremely common in functional programming, but strangely seems to rarely be explicitly defined as I've done here.
28
-
I learned about both from #cite(<felleisen18:htdp>, form: "prose").
28
+
I learned about both from _How to Design Programs_@felleisen18:htdp.
29
29
30
30
I'm not aware of any approachable yet thorough treatment of either algebraic data types or structural recursion.
31
31
Both seem to have become assumed background of any researcher in the field of programming languages,
32
32
and relatively recent work is caked in layers of mathematics and obtuse notation that I find difficult reading.
33
33
The infamous _Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire_@meijer91:bananas is an example of such work.
34
34
I suspect the core ideas of both date back to at least the emergence of computability theory in the 1930s, well before any digital computers existed.
35
35
36
-
The earliest reference I've found to structural recursion is #cite(<burstall69:proving>, form: "prose").
37
-
Algebraic data types don't seem to have been fully developed, along with pattern matching, until #link("https://en.wikipedia.org/wiki/NPL_(programming_language)")[NPL] in 1977.
38
-
NPL was quickly followed by the more influential language #link("https://en.wikipedia.org/wiki/Hope_(programming_language)")[Hope], which spread the concept to other programming languages.
36
+
The earliest reference I've found to structural recursion is _Proving Properties of Programs by Structural Induction_@burstall69:proving.
37
+
Algebraic data types don't seem to have been fully developed, along with pattern matching, until #href("https://en.wikipedia.org/wiki/NPL_(programming_language)")[NPL] in 1977.
38
+
NPL was quickly followed by the more influential language #href("https://en.wikipedia.org/wiki/Hope_(programming_language)")[Hope], which spread the concept to other programming languages.
39
39
40
-
Corecursion is a bit better documented in the contemporary literature. _How to Design Co-Programs_#cite(<gibbons21:htdcp>, form: "prose") covers the main ideas we have looked at here, while #cite(<gibbons98:unfold>, form: "prose") discusses uses of `unfold`.
40
+
Corecursion is a bit better documented in the contemporary literature. _How to Design Co-Programs_@gibbons21:htdcpcovers the main ideas we have looked at here, while _The under-appreciated unfold_@gibbons98:unfold discusses uses of `unfold`.
41
41
42
-
#cite(<mcbride01:deriv>, form: "prose") describes the derivative of algebraic data types.
42
+
_The Derivative of a Regular Type is its Type of One-Hole Contexts_@mcbride01:deriv describes the derivative of algebraic data types.
Copy file name to clipboardExpand all lines: src/pages/adt/scala.typ
+3-4Lines changed: 3 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
#import"../stdlib.typ": info, warning, solution
1
+
#import"../stdlib.typ": exercise, solution
2
2
== Algebraic Data Types in Scala
3
3
4
4
@@ -47,7 +47,7 @@ enum A {
47
47
}
48
48
```
49
49
50
-
In other words we don't write `final case class` inside an `enum`. You also can't nest `enum` inside `enum`. Nested logical ors can be rewritten into a single logical or containing only logical ands (known as disjunctive normal form) so this is not a limitation in practice. However the Scala 2 representation is still available in Scala 3 should you want more expressivity.
50
+
In other words we don't write `final case class` inside an `enum`. You also can't nest an `enum` inside an`enum`. Nested logical ors can be rewritten into a single logical or containing only logical ands (known as disjunctive normal form) so this is not a limitation in practice. However the Scala 2 representation is still available in Scala 3 should you want more expressivity.
51
51
52
52
53
53
=== Algebraic Data Types in Scala 2
@@ -212,8 +212,7 @@ We've seen that the Scala 3 representation of algebraic data types, using `enum`
212
212
- Scala 2's representation can express things that are almost, but not quite, algebraic data types. For example, if you define a method on an `enum` you must be able to define it for all the members of the `enum`. Sometimes you want a case of an `enum` to have methods that are only defined for that case. To implement this you'll need to use the Scala 2 representation instead.
213
213
214
214
215
-
==== Exercise: Tree {-}
216
-
215
+
#exercise[Tree]
217
216
218
217
To gain a bit of practice defining algebraic data types, code the following description in Scala (your choice of version, or do both.)
@@ -315,7 +315,7 @@ In these situations we can use dynamic dispatch instead.
315
315
We'll learn more about this when we look at generalized algebraic data types.
316
316
317
317
318
-
==== Exercise: Methods for Tree {-}
318
+
#exercise[Methods for Tree]
319
319
320
320
321
321
In a previous exercise we created a `Tree` algebraic data type:
@@ -572,7 +572,7 @@ Returning to `MyList`, it has:
572
572
- `Pair` is a constructor with one parameter of type `A` and one recursive parameter, and hence the corresponding function has type `(A, B) => B`.
573
573
574
574
575
-
==== Exercise: Tree Fold {-}
575
+
#exercise[Tree Fold]
576
576
577
577
578
578
Implement a fold for `Tree` defined earlier.
@@ -640,7 +640,7 @@ enum Tree[A] {
640
640
]
641
641
642
642
643
-
==== Exercise: Using Fold {-}
643
+
#exercise[Using Fold]
644
644
645
645
646
646
Prove to yourself that you can replace structural recursion with calls to fold, by redefining `size`, `contains`, and `map` for `Tree` using only fold.
0 commit comments