Docsity

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

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

)