I got gpt-4-vision to transcribe the image from that tweet, looks like it's from [1], "Functional programming in OCAML".
> This balance function can be written simply and concisely using pattern matching, where each of the four input cases is mapped to the same output case. In addition, there is the case where the tree is left unchanged locally.
let balance = function
| Black, z, Node (Red, y, Node (Red, x, a, b), c), d
| Black, z, Node (Red, x, a, Node (Red, y, b, c)), d
| Black, x, a, Node (Red, z, Node (Red, y, b, c), d)
| Black, x, a, Node (Red, y, b, Node (Red, z, c, d)) ->
Node (Red, y, Node (Black, x, a, b), Node (Black, z, c, d))
| a, b, c, d -> Node (a, b, c, d)
val balance : color \* 'a \* 'a rbtree \* 'a rbtree -> 'a rbtree = <fun>
Pattern matching is pretty much mainstream now. Ocaml, while not as common, is widely used. I think it's a great choice for teaching functional programming.
The book itself (linked in another comment) seems nice, although somewhat a bit general (e.g. a book with a more narrow focus on data structures would touch purely functional data structures, like finger trees) but this is perfect given the course scope. https://courses.cs.cornell.edu/cs3110/2021sp/textbook/intro/...
> This balance function can be written simply and concisely using pattern matching, where each of the four input cases is mapped to the same output case. In addition, there is the case where the tree is left unchanged locally.
[1] https://courses.cs.cornell.edu/cs3110/2021sp/textbook/eff/rb...