15-312 Foundations of Programming Languages
Lecture 16: Mutable Storage
In this lecture we introduce mutable storage into MinML in two different
ways. The first models the design ML: the type system does not track
effects (that is, the allocation, writing, or reading or mutable store).
This means we have to change all prior rules in the operational semantics
to allow for the store.
The second approach is taken in the Haskell language, where the
effects are encapsulated in a monad. All the types (including
the function types) remain pure and all evaluation rules remain
intact. In addition we have potentially effectful constructs
and ways to sequence them explicitly.
Both approaches have advantages and disadvantages: monads can lead
to somewhat contorted programs simply because we must make
all effects explicit in the types, but leaving them out in
the style of ML means that much less can be inferred from the type
of an expression which complicates reasoning about programs.