Navigation
index
next
|
previous
|
Intro to CS 2022
»
Lecture Notes, Week 12
ΒΆ
Mutable data in OCaml
References in OCaml
Constructing mutable values
Dereferencing mutable values
Mutating references
The imperative simulation of String.mapi in terms of String.map
Exercise NN
Interlude
Thunks by need, revisited
Resources
Version
A musing about variables
Semantics: what does “variable” mean?
Semiotics: meanings in names
Postlude
Acknowledgment
Version
Sequencing in OCaml
Sequencing in retrospect
On the associativity of sequencing
Exercise 01
Solution for Exercise 01
More syntactic sugar: begin and end
Sequencing, iteratively: for-loops
Exercise 02
Exercise 03
Exercise 04
Functional solution for Exercise 04
Imperative solution for Exercise 04
Imperative solution for Exercise 04, with a for-loop
Exercise 05
Exercise 06
Exercise 07
Exercise 08
Exercise 09
Exercise 10
Sequencing, iteratively: while-loops
Exercise 11
Exercise 12
Exercise 13
Exercise 14
Resources
Version
Exceptions in OCaml
Computing the head of a list all by ourselves
Computing the tail of a list all by ourselves
Computing list heads and tails using OCaml’s predefined functions
Division by 0
Another error case
Raising an exception in OCaml
Computing the head of a list using a predefined exception
Computing the tail of a list using a predefined exception
Our own error cases using a predefined exception
Resources
Version
Programming using exceptions
Resources
Catching exceptions in OCaml
A first example
Exercise AA
Exercise BB
Exercise CC
A second example
Interlude
Declaring new exceptions in OCaml
Application: multiplying all the integers in a binary tree
Exercise 15
Solution for Exercise 15
Exercise 16
Solution for Exercise 16
Application: multiplying all the integers in a binary tree (continued)
Exercise 17
Hint about Exercise 17
Application: testing whether a leaf satisfies a given predicate in a binary tree
Exercise 18
Exercise 19
Exercise 20
Exercise 21
Resources
Version
Imperative lists
Resources
Warmup
Unparsing imperative lists
Circular lists
How to construct a circular list
Interlude
A generic unit-test function for circular lists
How to detect whether an imperative list is circular: the unit-test functions
How to detect whether an imperative list is circular: Take 0
How to detect whether an imperative list is circular: Take 1
How to detect whether an imperative list is circular: Take 2
How to compute the length of an imperative list
How to fold right over imperative lists
How to fold left over imperative lists
How to detect whether an imperative list is circular using fold-right
How to detect whether an imperative list is circular using fold-left
How to compute the length of an imperative list using fold-left
How to compute the length of an imperative list using fold-right
How to compute the length of an imperative list using an exception
How to concatenate two imperative lists
How to reverse an imperative list
How to map a function over an imperative list
Exercise 22
Exercise 23
Exercise 24
Resources
Version
Exercises for Week 12
Exercise 0
Mandatory exercises
Optional exercises
Mini-projects
Version
Previous topic
Exercises for Week 11
Next topic
Mutable data in OCaml
Quick search
Enter search terms or a module, class or function name.
Navigation
index
next
|
previous
|
Intro to CS 2022
»