Understanding Mutability and Aliasing in Programming Languages: A Focus on OCaml - Prof. B, Study notes of Computer Science

An introduction to mutability and aliasing in programming languages, with a focus on ocaml. It explains how variables are treated in different languages, the concept of reference cells or references, and the implications of aliasing on program reasoning and compiler optimization. It also discusses the benefits and difficulties of aliasing.

Typology: Study notes

Pre 2010

Uploaded on 03/28/2010

koofers-user-x5r
koofers-user-x5r 🇺🇸

4.3

(3)

10 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CIS 500
Software Foundations
Fall 2003
22 October
CIS 500, 22 October 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Understanding Mutability and Aliasing in Programming Languages: A Focus on OCaml - Prof. B and more Study notes Computer Science in PDF only on Docsity!

CIS 500

Software Foundations

Fall 2003

22 October

References

So a variable of typeWe choose OCaml’s style, which is easier to work with formally.

in most languages (except OCaml) will correspond

to a

(actually, a

) here.

Basic Examples

Aliasing

A value of type

is a

pointer

to a cell holding a value of type

.

r =

5

pointed to is not copied. If this value is “copied” by assigning it to another variable, the cell

r =

5

s =

So we can change

by assigning to

 :

    

Aliasing all around us

possibility of aliasing. Reference cells are not the only language feature that introduces the

arrays

communication channels

I/O devices (disks, etc.)

The benefits of aliasing

involving aliasing:But there are good reasons why most languages do provide constructsdisallow it (e.g., Haskell). The problems of aliasing have led some language designers simply to

efficiency (e.g., arrays)

“action at a distance” (e.g., symbol tables)

shared resources (e.g., locks) in concurrent systems

etc.

Example

                  



Syntax

::=

terms

unit constant

variable

abstraction

application

reference creation

dereference

assignment

... plus other familiar types, in examples.

Typing Rules

    

         

(T-R

EF

)

       

    

(T-D

EREF

)

            

          

(T-A

SSIGN

)