1
On Understanding Data Abstraction ... Revisited
1
On Understanding Data Abstraction ... Revisited 1 1 William R. - - PowerPoint PPT Presentation
On Understanding Data Abstraction ... Revisited 1 1 William R. Cook The University of Texas at Austin Dedicated to P. Wegner 2 2 Objects ???? Abstract Data Types 3 3 Warnings! 4 4 No Objects Model the Real World 5 5 No
1
1
2
William R. Cook The University
Dedicated to P. Wegner
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
(very nice but not essential)
10
11
discuss inheritance later
11
12
12
13 13
Hidden Visible
14 14
15
15
16
16
17
(one kind of)
17
18
signature Set empty
insert
isEmpty : Set → Bool contains : Set, Int → Bool
18
19
signature Set empty
insert
isEmpty : Set → Bool contains : Set, Int → Bool
19
20
20
21
abstype Set = List of Int empty
insert(s, n) = (n : s) isEmpty(s) = (s == []) contains(s, n) = (n ∈ s)
21
22
def x:Set = empty def y:Set = insert(x, 3) def z:Set = insert(y, 5) print( contains(z, 2) )==> false
22
23 23
Hidden representation: List of Int Visible name: Set
24 24
25
ISetModule = ∃Set.{ empty : Set insert : Set, Int → Set isEmpty : Set → Bool contains : Set, Int → Bool }
25
26
26
27
27
28
28
29
(existential types)
29
30
30
31
31
32
S = { 1, 3, 5, 7, 9 }
32
33
33
34
P(n) = even(n) & 1≤n≤9
34
35
S = { 1, 3, 5, 7, 9 } P(n) = even(n) & 1≤n≤9
35
36
36
37
37
38
38
39
39
40
def x:Set = Empty def y:Set = Insert(x, 3) def z:Set = Insert(y, 5) print( z(2) ) ==> false
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
def x:Set = Even def y:Set = Insert(x, 3) def x:Set = Insert(y, 5) print( z(2) ) ==> true
48
49
49
50
50
51
51
52
52
53
53
54
class Empty { contains(n) { return false;} isEmpty() { return true;} }
54
55
class Insert(s, m) { contains(n) { return (n=m) ∨ s.contains(n) } isEmpty() { return false } }
55
56
def x:Set = Empty() def y:Set = Insert(x, 3) def z:Set = Insert(y, 5) print( z.contains(2) ) ==> false
56
57
57
58
58
59
59
60
60
61
class Empty { contains(n) { return false;} isEmpty() { return true;} insert(n) { return Insert(this, n);} }
61
62
class Empty { contains(n) { return false;} isEmpty() { return true;} insert(n) { return Insert(this, n);} }
62
63
def x:Set = Empty def y:Set = x.insert(3) def z:Set = y.insert(5) print( z.contains(2) )==> false
63
64
64
65
65
66
66
67
67
68
68
69
class Union(a, b) { contains(n) { a.contains(n) ∨ b.contains(n); } isEmpty() { a.isEmpty(n) ∧ b.isEmpty(n); } ... }
69
(binary)
70
70
71
71
72
class Intersection(a, b) { contains(n) { a.contains(n) ∧ b.contains(n); } isEmpty() { ? no way! ? } ... }
72
73
73
74
74
75
75
76
76
ADT (existential types) SetImpl = ∃ Set . { empty : Set isEmpty : Set → Bool contains : Set, Int → Bool insert : Set, Int → Set union : Set, Set → Set }
77
Object Interface (recursive types) Set = { isEmpty : Bool contains : Int → Bool insert : Int → Set union : Set → Set } Empty : Set Insert : Set x Int → Set Union : Set x Set → Set
77
s Empty Insert(s', m) isEmpty(s) true false contains(s, n) false n=m ∨ contains(s', n) insert(s, n) false Insert(s, n) union(s, s'') isEmpty(s'') Union(s, s'')
Operations/Observations
78 78
s Empty Insert(s', m) isEmpty(s) true false contains(s, n) false n=m ∨ contains(s', n) insert(s, n) false Insert(s, n) union(s, s'') isEmpty(s'') Union(s, s'')
79
79
s Empty Insert(s', m) isEmpty(s) true false contains(s, n) false n=m ∨ contains(s', n) insert(s, n) false Insert(s, n) union(s, s'') isEmpty(s'') Union(s, s'')
80 80
81
81
82
82
83
(recursive types)
83
84
84
85
85
86
“Binary” Operations? Stack, Socket, Window, Service, DOM, Enterprise Data, ...
86
87
(functions passed as data and returned as results)
87
88
88
89
ADTs: construction Objects: observation
89
90
ADTs: induction Objects: coinduction complicated by: callbacks, state
90
91
91
92
92
93
93
94
94
95
95
96
96
97
97
98
98
99
99
100
100
101
101
102
102
103
class True ifTrue: a ifFalse: b ^a class False ifTrue: a ifFalse: b ^b
103
104
True = λ a . λ b . a False = λ a . λ b . b
104
105
(in one slide)
105
A Object Y(G) G Self- reference Δ(A) A Δ Modificatio n Δ(Y(G)) G Δ Y(ΔoG) G Δ Inheritance Δ(Y(G)) G Δ
106
106
107
107
108
User-defined types and procedural data structures as complementary approaches to data abstraction by J. C. Reynolds New Advances in Algorithmic Languages INRIA,
108
Abstract data types User-defined types and procedural data structures as complementary approaches to data abstraction by J. C. Reynolds New Advances in Algorithmic Languages INRIA, 1975
109 109
110
“[an object with two methods] is more a tour de force than a specimen of clear programming.”
110
Extensibility Problem (aka Expression Problem)
111
1975 Discovered by J. Reynolds 1990 Elaborated by W. Cook 1998 Renamed by P. Wadler 2005 Solved by M. Odersky (?) 2025 Widely understood (?)
111
112
112
113
113
114
114
115
115